Package me.scolastico.tools.handler
Class ErrorHandler
- java.lang.Object
-
- me.scolastico.tools.handler.ErrorHandler
-
- All Implemented Interfaces:
java.lang.Thread.UncaughtExceptionHandler
public class ErrorHandler extends java.lang.Object implements java.lang.Thread.UncaughtExceptionHandler
Handle your errors automatically. Send them to sentry, output them to the console and/or write them to the error log!
-
-
Constructor Summary
Constructors Constructor Description ErrorHandler()
Its not recommended to use the instance.
-
Method Summary
Modifier and Type Method Description static void
enableCatchUncaughtException()
Enable the exception handling for uncaught exceptions.static void
enableErrorLogFile()
Enable the 'error.log' file to which the stack traces will also be written.static void
enableSentry(java.lang.String sentryDns)
To enable sentry reporting past the sentry dns string to this function!static void
enableSentry(java.lang.String sentryDns, double tracesSampleRate, java.lang.String release)
To enable sentry reporting past the sentry dns string to this function!static void
handle(java.lang.Throwable e)
Handle an exception.static void
handle(java.lang.Throwable e, io.sentry.SentryLevel level, java.lang.String... debugInformation)
Handle an exception and send more data to Sentry.static void
handleFatal(java.lang.Throwable e)
Handle an exception and exit the program with exit a non zero exit code.static void
handleFatal(java.lang.Throwable e, int exitCode)
Handle an exception and exit the program with exit a non zero exit code.void
uncaughtException(java.lang.Thread t, java.lang.Throwable e)
Internal function from the UncaughtExceptionHandler implementation.
-
-
-
Method Detail
-
enableSentry
public static void enableSentry(java.lang.String sentryDns)
To enable sentry reporting past the sentry dns string to this function!- Parameters:
sentryDns
- The sentry dns string for error reporting to sentry.io!
-
enableSentry
public static void enableSentry(java.lang.String sentryDns, double tracesSampleRate, java.lang.String release)
To enable sentry reporting past the sentry dns string to this function!- Parameters:
sentryDns
- The sentry dns string for error reporting to sentry.io!tracesSampleRate
- https://docs.sentry.io/platforms/java/configuration/sampling/release
- https://docs.sentry.io/platforms/java/configuration/releases/
-
enableCatchUncaughtException
public static void enableCatchUncaughtException()
Enable the exception handling for uncaught exceptions. Uncaught exceptions will trigger a fatal exception!
-
enableErrorLogFile
public static void enableErrorLogFile()
Enable the 'error.log' file to which the stack traces will also be written.
-
handle
public static void handle(java.lang.Throwable e)
Handle an exception.- Parameters:
e
- The exception to handle.
-
handle
public static void handle(java.lang.Throwable e, io.sentry.SentryLevel level, java.lang.String... debugInformation)
Handle an exception and send more data to Sentry.- Parameters:
e
- The exception to handle.level
- The error level for Sentry.debugInformation
- The debug infos.
-
handleFatal
public static void handleFatal(java.lang.Throwable e)
Handle an exception and exit the program with exit a non zero exit code.- Parameters:
e
- The exception to handle.
-
handleFatal
public static void handleFatal(java.lang.Throwable e, int exitCode)
Handle an exception and exit the program with exit a non zero exit code.- Parameters:
e
- The exception to handle.exitCode
- The exit code to report.
-
uncaughtException
public void uncaughtException(java.lang.Thread t, java.lang.Throwable e)
Internal function from the UncaughtExceptionHandler implementation.- Specified by:
uncaughtException
in interfacejava.lang.Thread.UncaughtExceptionHandler
- Parameters:
t
- The current thread.e
- The uncaught exception.
-
-