Accessing the ExceptionList tree using Java

The ExceptionList tree is created with the logical tree when an input message is parsed.

About this task

The tree is initially empty, and is only populated if an exception occurs during message flow processing. It is possible that more than one exception can occur; if more than one exception occurs, the ExceptionList tree contains a subtree for each exception.

You can access the ExceptionList tree in JavaCompute nodes from the MbMessageAssembly parameter of your evaluate() method.

You can access the ExceptionList tree in a node in an error handling procedure. For example, you might want to route the message to a different path based on the type of exception.

You can use the querying capabilities within XPath to carry out this task. The descendant axis (//) of XPath gives you the ability to search for an element by name regardless of its depth in the tree. For example:
    //ParserException
returns all elements in the tree named ParserException.
If you are specifically interested in a particular message, you can use a predicate (see predicates for further information) to narrow down the result set. For example:
    //ParserException[Number=5016]
returns only the exception that contains Number=5016.
If you only want to extract the text message associated with this exception, the following XPath expression returns this as a java.lang.String:
    string(//ParserException[Number=5016]/Text)

The following Java™ code extracts this text from your code:

String text = 
(String)inAssembly.getExceptionList().evaluateXPath("string(//ParserException[Number=5016]/Text)");         

For information on accessing the ExceptionList tree using ESQL, see Accessing the ExceptionList tree using ESQL.