Created
July 9, 2026 13:32
-
-
Save aoudiamoncef/24c78f24c0ff2fb5507b6799e2196909 to your computer and use it in GitHub Desktop.
Global Application Exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.labs.app.api.domain.exception; | |
| import java.util.function.Supplier; | |
| public class AppException extends RuntimeException { | |
| private final int errorCode; | |
| public AppException(final String reason) { | |
| super(reason); | |
| this.errorCode = -1; | |
| } | |
| public AppException(final int code, final String reason) { | |
| super(reason); | |
| this.errorCode = code; | |
| } | |
| public AppException(final String message, final Throwable cause) { | |
| super(message, cause); | |
| this.errorCode = -1; | |
| } | |
| public AppException(final String message, final int code, final Throwable cause) { | |
| super(message, cause); | |
| this.errorCode = code; | |
| } | |
| public int getErrorCode() { | |
| return errorCode; | |
| } | |
| public static Supplier<AppException> toSupplier(final String reason) { | |
| return () -> new AppException(reason); | |
| } | |
| public static Supplier<AppException> toSupplier(final int code, final String reason) { | |
| return () -> new AppException(code, reason); | |
| } | |
| public static Runnable toRunnable(final int code, final String reason) { | |
| return () -> { | |
| throw new AppException(code, reason); | |
| }; | |
| } | |
| public static Supplier<AppException> toSupplier(final String reason, final Throwable cause) { | |
| return () -> new AppException(reason, cause); | |
| } | |
| public static Supplier<AppException> toSupplier(final String reason, final int code, final Throwable cause) { | |
| return () -> new AppException(reason, code, cause); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment