Class ExceptionContext


  • public final class ExceptionContext
    extends java.lang.Object
    The exception context allows the safe execution of code that may throw an exception. Exceptions are captured and available for further investigations.

    The main use case is to capture multiple exceptions of multiple invocations to facilitate joint fixing of underlying problems.

    For example, consider a configuration that is lacking in several ways. In a fail-fast setting, an exception is thrown for the first issue, which may be subsequently fixed. However, further executions find more issue, which requires additional feedback loops. If such a loop is slow or asynchronous, a tremendous amount of time is spent until getting it right. Capturing all issues at once significantly decreases the number of loops and may speed up the process accordingly.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      @NonNull java.util.List<java.lang.Exception> getExceptions()
      The captured exceptions.
      int hashCode()  
      void safeExecute​(@NonNull java.lang.Runnable runnable)
      Safely executes the given runnable.
      <T> java.util.Optional<T> safeExecute​(@NonNull java.util.concurrent.Callable<? extends T> function)
      Safely executes the given function.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ExceptionContext

        public ExceptionContext()
    • Method Detail

      • safeExecute

        public <T> java.util.Optional<T> safeExecute​(@NonNull
                                                     @NonNull java.util.concurrent.Callable<? extends T> function)
        Safely executes the given function. Any exception is caught and Optional.empty() is returned.
        Type Parameters:
        T - the return type of the function
        Parameters:
        function - the function to execute
        Returns:
        the return value of the function wrapped in an Optional if no exception occurred, Optional.empty() otherwise.
      • safeExecute

        public void safeExecute​(@NonNull
                                @NonNull java.lang.Runnable runnable)
        Safely executes the given runnable. Any exception is caught.
        Parameters:
        runnable - the runnable to execute
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getExceptions

        @NonNull
        public @NonNull java.util.List<java.lang.Exception> getExceptions()
        The captured exceptions.