Cernunnos Manual


<handle-error>

Description:

Executes the tasks defined by TRY. If an error occurs, this task will attempt to match the runtime type of the error with a CATCH_CLASS. If there is a match, this task will execute the associated CATCH_BLOCK; if not, it will re-throw the original error.

WARNING: be careful using CATCH_CLASS. It may be difficult to guess the actual runtime type of the error that will be caught, even if you understand where the Cernunnos XML is likely to fail, since the original error may be wrapped one or more times before it's compared to CATCH_CLASS. The <handle-error> task will, however, unwrap a ManagedException and use its cause in comparisons.

Reagents:

Name XPath Description Reagent Type Expected Type Required
TRY try/* A collection of tasks to perform. If an error occurs within these tasks, it will be caught and excution will continue appropriately. NODE_LIST java.util.List Yes
CATCH_CLASS catch/@class Optional Java class (<? extends Throwable>) that, if caught, will trigger the CATCH_BLOCK to which it applies. The default is Throwable.class. NODE_LIST java.util.List No
CATCH_BLOCK catch Each CATCH_BLOCK specifies a collection of tasks that will be invoked if the corresponding CATCH_CLASS is caught. NODE_LIST java.util.List No
FINALLY_BLOCK finally/* A collection of tasks to perform after the try and catch blocks are complete. The finally block will be executed regardless of any exception being thrown. NODE_LIST java.util.List No

Examples:

Writes 'I caught something else...' to the console window:

 
       
        <handle-error> 
          <try> 
            <groovy> 
              <script>throw new RuntimeException('Not good.');</script> 
            </groovy> 
          </try>  
          <catch class="${groovy(IllegalArgumentException.class)}"> 
            <echo-ln>I caught an IllegalArgumentException...</echo-ln> 
          </catch>  
          <catch> 
            <echo-ln>I caught something else...</echo-ln> 
          </catch> 
        </handle-error>