Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | DSPs and building output templates | Using Dynamic Server Pages (DSPs) | Using the DSP Tags | Catching Errors
 
Catching Errors
If you want your DSP to react in a specified way when the invoked service fails, include an %onerror% tag within your %invoke%…%end% construct. The code in the %onerror% block executes only if an exception occurs while the service executes or the service returns an error.
When the %onerror% block executes, the scope contains the following values:
Key...
Description
error
A String containing the Java class name of the exception that was thrown (e.g., com.wm.app.b2b.server.AccessException).
errorMessage
A String containing the exception message in English, regardless of the locale of the server or client.
localizedMessage
A String containing the exception message, translated into the language used by the client that invoked the DSP.
errorInput
The IData object that was passed to the invoked service.
errorOutput
The IData object returned by the invoked service. If the service returned an error, errorOutput will contain $error and any other variables that were in the pipeline when the service ended.
Important:
If the service experiences an exception (i.e., the server is not able to execute it successfully), errorOutput will not be exist. This variable is only produced when the service returns an error.
errorService
The name of the invoked service.
The following example shows how you might use an %onerror% clause to return an error message to the user.
.
.
.
%invoke orders:getShipInfo%
<H2>Shipping Details for Order %value /oNum%</H2>
<P>Date Shipped: %value shipDate%<BR>
.
.
.
%onerror%

<HR>
<P><FONT COLOR="#FF0000">The
Server could not process your request

because the following error occurred.
Contact your server

administrator.</FONT></P>
<TABLE WIDTH="50%" BORDER="1">
<TR><TD><B>Service</B></TD><TD>%value
errorService%</TD></TR>

<TR><TD><B>Error</B></TD><TD>%value
Error% &nbsp;

%value errorMessage%</TD></TR>
</TABLE>
<HR>

%endinvoke%
.
.
.