Class SequentialScopeExceptionHandling

java.lang.Object
org.logicmachine.rebl.integrationTests_5_exceptionHandling.ExceptionHandlingBase
org.logicmachine.rebl.integrationTests_5_exceptionHandling.SequentialScopeExceptionHandling
All Implemented Interfaces:
Callable<Object>

public class SequentialScopeExceptionHandling extends ExceptionHandlingBase
This class contains use-case examples of exception handling in sequential scopes.

This illustrates how exception handlers can (optionally) be attached to a scope and how each exception handler can decide if it knows how to handle a specific exception.

Exceptions will bubble-up through the hierarchy of scopes until either an exception handler deals with this specific exception, or the top-level (catch-all) default exception handler deals with it.

This catch-all exception handler is associated with the implicit top-level default scope. Indeed the primary purpose of the top-level default scope is simply to hold this default exception handler.
  • Constructor Details

    • SequentialScopeExceptionHandling

      public SequentialScopeExceptionHandling()
      Default constructor.
  • Method Details

    • main

      public static void main(String[] args)
      Platform entry-point, invoking the core application functionality.
      Parameters:
      args - the standard platform arguments (not used)
    • shouldCatchExceptionInDefaultScope

      public void shouldCatchExceptionInDefaultScope()
      Should trigger an exception in scope C which will bubble up through scope A before being caught in the top-level default scope and handled by the exception handler associated with the default scope.
    • shouldCatchExceptionInParentScope

      public void shouldCatchExceptionInParentScope()
      Should trigger an exception in scope F which will bubble up through scope E (where the exception matcher will not match the exception and therefore the exception handler in scope E will ignore it) before being caught in the parent scope D and handled by the exception handler associated with scope D.
    • setupScopes

      protected void setupScopes()
      Creates the scopes required by this example.

      This method will define the following scope hierarchy:

      A(C), B(D(E(F)))

      Which can also be depicted as follows:


      DefaultScope
      |
      |---> A
      |     |---> C
      |
      |---> B
      |     |---> D
      |           |---> E
      |                 |---> F


      In this example, an exception will be thrown in scope C which will bubble up through scope A and into the exception handler associated with the implicit top-level default scope.

      Similarly, an exception will be thrown in scope F, which will bubble up through scope E (where it will be ignored by the scope E exception handler since it will not match the type of exception monitored by this exception handler) before being handled by the exception handler associated with scope D.
      Specified by:
      setupScopes in class ExceptionHandlingBase
    • setupExceptionHandlers

      protected void setupExceptionHandlers()
      Description copied from class: ExceptionHandlingBase
      This method creates a number of exception handler instances and attaches these to various scopes.
      Specified by:
      setupExceptionHandlers in class ExceptionHandlingBase
    • verify

      protected void verify()
      Description copied from class: ExceptionHandlingBase
      Verifies that the expected exception has been thrown and has been handled by the correct exception handler.
      Specified by:
      verify in class ExceptionHandlingBase