Interface ExceptionHandlerAware

All Known Implementing Classes:
AmexChannel, ASCIIChannel, BASE24Channel, BASE24TCPChannel, BaseChannel, BCDChannel, CMFChannel, CSChannel, FSDChannel, GICCChannel, GZIPChannel, HEXChannel, LogChannel, NACChannel, NCCChannel, PADChannel, PostChannel, RawChannel, RBPChannel, TelnetXMLChannel, VAPChannel, X25Channel, XMLChannel

public interface ExceptionHandlerAware
Interface that modifies an implementing class to add an exception handling pipeline.

The main pipeline consists of multiple sub-pipelines:

  • A pipeline for which handlers are called regardless of the type of exception handled. Stored under a null key.
  • A pipeline per targeted exception type.
The targeted pipeline always executes before the default pipeline.

In the event that both of the pipelines are empty, the default behavior is to rethrow the initial exception.

There is no need to implement the methods unless you override the default behavior.

Since:
2.1.2
  • Method Details

    • getExceptionHandlers

      Returns:
      A map of exception classes to exception handlers. These handlers only execute if the exception matches.
    • addHandler

      default void addHandler(ExceptionHandler handler)
      Add a handler to the default pipeline.
      Parameters:
      handler - ExceptionHandler to add.
    • addHandler

      default void addHandler(ExceptionHandler handler, Class<? extends Exception> clazz)
      Add a handler to an exception specific pipeline.
      Parameters:
      handler - ExceptionHandler to add.
      clazz - Exception handler pipeline to add it to.
    • removeHandler

      default void removeHandler(ExceptionHandler handler)
      Remove a handler from the default pipeline.
      Parameters:
      handler - ExceptionHandler to remove.
    • removeHandler

      default void removeHandler(ExceptionHandler handler, Class<? extends Exception> clazz)
      Remove a handler from an exception specific handler pipeline. The list of exception handlers is removed once the last handler has been removed.
      Parameters:
      handler - ExceptionHandler to remove.
      clazz - Exception pipeline to remove it from.
    • removeHandlers

      default void removeHandlers(Class<? extends Exception> clazz)
      Remove all handler for a specific exception handling pipeline.
      Parameters:
      clazz - Exception pipeline to remove.
    • handle

      default Exception handle(Exception e) throws Exception
      Execute the pipeline by starting with the specific pipeline for the exception followed by the default pipeline.
      In the event of both pipelines being empty, the original exception is rethrown.
      Parameters:
      e - Initial exception.
      Returns:
      Same, modified or new exception.
      Throws:
      Exception - In the event of a handler throwing an exception. Processing by further handlers would be cancelled.