-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57da6b7
commit c04d4a9
Showing
4 changed files
with
118 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
79 changes: 79 additions & 0 deletions
79
src/main/java/xyz/snaker/hiss/thread/PeripheralException.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package xyz.snaker.hiss.thread; | ||
|
||
import xyz.snaker.hiss.logger.Logger; | ||
import xyz.snaker.hiss.logger.Loggers; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Created by SnakerBone on 19/08/2023 | ||
**/ | ||
public class PeripheralException extends Thread | ||
{ | ||
private static final Logger LOGGER = Loggers.getLogger(); | ||
private static final Function<String, String> ERROR_TEMPLATE = "Peripheral Exception Thrown: %s"::formatted; | ||
private static final String NO_ERROR_MESSAGE = ERROR_TEMPLATE.apply("No message specified"); | ||
|
||
private final String message; | ||
private final UncaughtExceptionHandler handler; | ||
private final Exception cause; | ||
|
||
private PeripheralException(String message, Exception cause) | ||
{ | ||
this.message = message; | ||
this.handler = (t, e) -> LOGGER.errorf(ERROR_TEMPLATE.apply(message)); | ||
this.cause = cause; | ||
} | ||
|
||
private PeripheralException(Exception cause) | ||
{ | ||
this(cause.getMessage(), cause); | ||
} | ||
|
||
private PeripheralException(String message) | ||
{ | ||
this(message, new Exception()); | ||
} | ||
|
||
private PeripheralException() | ||
{ | ||
this(NO_ERROR_MESSAGE, new Exception()); | ||
} | ||
|
||
public static void invoke(String message, Exception cause) | ||
{ | ||
new PeripheralException(message, cause).start(); | ||
} | ||
|
||
public static void invoke(Exception cause) | ||
{ | ||
new PeripheralException(cause).start(); | ||
} | ||
|
||
public static void invoke(String message) | ||
{ | ||
new PeripheralException(message).start(); | ||
} | ||
|
||
public static void invoke() | ||
{ | ||
new PeripheralException().start(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings({"ConstantValue", "CallToPrintStackTrace"}) | ||
public void run() | ||
{ | ||
cause.printStackTrace(); | ||
|
||
if (true) { | ||
throw new RuntimeException(message); | ||
} | ||
} | ||
|
||
@Override | ||
public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh) | ||
{ | ||
super.setUncaughtExceptionHandler(handler); | ||
} | ||
} |
71 changes: 0 additions & 71 deletions
71
src/main/java/xyz/snaker/hiss/thread/UncaughtExceptionThread.java
This file was deleted.
Oops, something went wrong.
This file contains 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