Class ExceptionHandlingUtils


  • public final class ExceptionHandlingUtils
    extends Object
    • Method Detail

      • tryCatch

        public static void tryCatch​(Runnable executable,
                                    Consumer<Throwable> errorNotifier)
        Runs a task within try-catch block. All exceptions thrown from the execution will be sent to errorNotifier.

        This is useful for single-line executable code to avoid try-catch code clutter.

        Parameters:
        executable - the task to run
        errorNotifier - error notifier
      • tryCatchFinally

        public static <T> T tryCatchFinally​(Callable<T> executable,
                                            Consumer<Throwable> errorNotifier,
                                            Runnable cleanupExecutable)
        Runs a task within try-catch-finally block. All exceptions thrown from the execution will be sent to errorNotifier.

        This is useful for single-line executable code to avoid try-catch code clutter.

        Type Parameters:
        T - the type of the object to be returned
        Parameters:
        executable - the task to run
        errorNotifier - the error notifier
        cleanupExecutable - the cleanup executable
        Returns:
        the object if succeeds