Class LoggingUncaughtThreadDeathContextRunnable

  • All Implemented Interfaces:
    Runnable

    public abstract class LoggingUncaughtThreadDeathContextRunnable
    extends Object
    implements Runnable
    Runnable with final run() method that catches any unexpected checked exceptions (RuntimeException & Error) and logs them with some kind of context which allows to better identify the root cause.
    Author:
    Michael Vorburger.ch
    • Constructor Detail

      • LoggingUncaughtThreadDeathContextRunnable

        protected LoggingUncaughtThreadDeathContextRunnable​(org.slf4j.Logger logger,
                                                            Supplier<String> debugLogContextSupplier)
        Constructor.
        Parameters:
        logger - the Logger of the class which created this Runnable
        debugLogContextSupplier - supplies useful context included in error log in case of caught checked exception
    • Method Detail

      • wrap

        public static Runnable wrap​(Runnable runnable,
                                    org.slf4j.Logger logger,
                                    Supplier<String> debugLogContextSupplier)
        Wraps an existing Runnable.
        Parameters:
        logger - the Logger of the class which created this Runnable
        debugLogContextSupplier - supplies useful context included in error log in case of caught checked exception
      • runWithUncheckedExceptionLogging

        protected abstract void runWithUncheckedExceptionLogging()
        Run method which you implement instead of the original run().