# Getting the TransformException Fault Code Programmatically

In the mapper functionality of WebLogic Workshop, you create transformations that transform data from one format to another. From these transformations, queries (written in the XQuery) language are generated. You can use the mapper functionality to edit these queries to add invocations to standard XQuery functions and operators, User functions, or Controls functions. To learn more, see Invoking Functions or Operators in a Query.

During run time, these queries may throw a TransformException exception with an associated fault code. (For example, your query might call one of the provided standard XQuery functions, which may throw an exception.) The fault code provides information about why the TransformException was thrown. You may want to add Java code to business process to get the fault code of the TranformException and do some action in the code based on the fault code. You may also display the description string associated with the fault code in the console using a System.out.println function. You add this code to the Process Definition for Java (JPD) file which contains the Java code for the business process.

Note: If you are only interested in the fault code string, use the Exception pane of the Workshop Test Browser or the Test View pane of the mapper functionality of WebLogic Workshop to display the error string associated with the fault code.

For example, a business process whose Start node is a Client Receive node invokes a Transformation method of a Transformation file. The Client Receive node has an exception path with a Perform node to catch exception, as shown in the following figure:

The Transformation method invokes a query, which invokes the standard XQuery function xf:date. During run time when the query is executed, the date function is invoked with the string: 2003-8-16. This string is not a legal date format because the month is not specified with two digits. This causes the date function to thrown a TransformException exception with the TransformFaultCodes.RT_ILLEGAL_CAST fault code. The Perform node retrieves the information about the exception that invoked it, checks that the exception is a TransformException, and then prints out fault code number and sting that describes the fault code, as shown in the following JPD code segment:

    import com.bea.jpd.JpdContext;
    import com.bea.data.RawData;
    import com.bea.xml.XmlObject;
    import com.bea.transform.TransformException;
    import com.bea.transform.TransformFaultCodes;
    ...
    public class TransformExceptionExample implements com.bea.jpd.ProcessDefinition
    {
    	...
    	public void perform() throws Exception
    	{
    		Exception e;
    		com.bea.transform.TransformException te;
    		e = this.context.getExceptionInfo().getException();
    		System.out.println("Caught exception in transformation: " + e.toString());
    		if (e instanceof TransformException)
    		{
    			te = (TransformException) e;
    			System.out.println("Fault Code Number=" + te.getFaultCode());
    			System.out.println("Fault Code String=" + te.getCause());
               switch (te.getFaultCode()) {
    					case TransformFaultCodes.RT_ILLEGAL_CAST:
    					// Add code here to do some action based on the error code.
    					break;
    				default:
    					break;
    			}
    		}
    	}
    }

For example, if some corrective action should occur if the returned fault code is equal to the TransformFaultCodes.RT_ILLEGAL_CAST fault code, replace the comment that starts with the string: //Add code here with the corrective Java code.

For a list of the supported fault codes, see the JavaDoc for the TransformFaultCodes class.

Note: The following two import lines must be added manually in the Source View of the JPD file:

import com.bea.transform.TransformException;
import com.bea.transform.TransformFaultCodes;