Exception Handling

Hello, I’m relatively new to WM Development, and have a question about Error Trapping. I want to wrap a DB insert in a Try-Catch block, and when an error occurs (lets say for a null value insert into a not-null column), I want to format that error into a published error document. The problem I’m having is retrieving the exception error to use to populate my new document. Is there any way of accessing the exceptions error message from the catch side of a try-catch block?

Any help on this would be greatly apprecaited. I’ve scoured the wm advantage site, as well as the related program documentation but up to this point I’ve been unable to accomplish this task.

Step 1:
Declare a class level variable
private Exception adapterexception ;
Step 2:
In the scriptInvoke method assign the exception to this variable:
adapterexception = catchStepEx ;
Step 3:
Insert a custom step in the catch side and retrieve the error message into a String and return that variable which can be mapped to a field in an error event.
String errormessage = adapterexception.getMessage();

Hope this helps.

Siby Paul

Create a Variable

private String exceptionText = “”;

Create a CustomStep “ExposeException”. Specify Return type as Unicode String. Go to its Script and type the following

return exceptionText;

Go to your main Catch and get the error message in to exceptionText. Following is how to do that in the code.

public void
scriptInvoke(AdapterScriptAccess access,
AdapterTransaction transaction,
BrokerEvent input)
throws AdapterException, BrokerException
{
this.access = access;
this.transaction = transaction;
reset();

    try { 
        operationStep(); 
        catchStepTry(); 
    } 
    catch (AdapterException catchStepEx) { 
        //Save the Exception here 
        exceptionText = catchStepEx.toString(); 
        exposeException(); 
        publishStep(); 
        catchStepCatch(); 
    } 

This should give you the ErrorText in the output

Hi Rory, .toString will get the error message - if you want the entire stack trace the following will work - you’ll need to add several things in the appropriate places in the script:

//imports
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

//attribute declarations
private ByteArrayOutputStream baoStream = null;
private PrintStream printStream = null;

//initialize like this
baoStream = new ByteArrayOutputStream();
printStream = new PrintStream(baoStream);

//then in the catch block…
e.printStackTrace(printStream);
String error = baoStream.toString();

If you are using the wM Enterprise Integrator, the code below is from ERROR CATCH Block in the EI that we used to get the caught error text.

try {
ErrorCatchStepTry();
}
catch (AdapterException ErrorCatchStepEx) {
declarationStep.stringExceptionMessage = ErrorCatchStepEx.getLocalizedMessage();
declarationStep.$strExceptionMsg = true;
ErrorCatchStepCatch();
}

declarationStep.stringExceptionMessage is a globle varible. So, you can use it everywhere within an EI component.

The line:

declarationStep.stringExceptionMessage = ErrorCatchStepEx.getLocalizedMessage();

will catch error text. Then, you can print declarationStep.stringExceptionMessage using access.println()

or you can assign the declarationStep.stringExceptionMessage to the error text field in Adapter::errorNotify and Adapter::error to publish and deliver.

Hi,

I am using Enterprise isiebel Adapter to insert data in to Siebel. When I try to insert the value in a field which has a pick list(LOV) associated with it, I get an error saying value does not match with any value in th bounded pick list. But the value exist in the pick list. When I use same value from Siebel front end application, it works. Does any one has idea, why it’s not considering the input to be one of the value in pick list?

I’m trying to implement the EI error logic suggested by ZGW and need a little help…

In my EI (version 6.0.1) I added the ErrorCatchStep to my flow diagram. In my try step I execute an operation. I assume I add the code mentionned in my Catch step… is this done by using the Custom Code Script?

Thanks!