Try Statement
The Try statement processes an exception. It handles functions that can raise an exception, which is an error condition that causes the script to branch to another routine. It can include the following clauses:
Catch clause. Handles the exception. To raise an exception, you use the Throw statement. For more information, see Throw Statement.
Finally clause. Performs cleanup work. For example, removing object references.
You can write code that does the following to trap errors that a statement block creates:
Place code that must trap errors in a Try statement.
Follow the Try statement with a catch clause. You can write code that uses the exception_handling_block argument in this catch clause to process the exception.
Format
try
{
statement_block
}
catch
{
exception_handling_block
[throw exception]
}
finally
{
statement_block_2
}
The following table describes the arguments for the Try statement.
Argument | Description |
---|---|
statement_block |
A statement block that can create an error. |
exception_handling_block |
A statement block that processes the error. |
exception |
An error of a named type. |
statement_block_2 |
A statement block that Siebel eScript always runs unless the Try statement transfers control to elsewhere in the script. |
Example
The following example demonstrates the format of a Try statement that includes a catch clause. In this example, Siebel eScript continues to run the script after it displays the error message:
try
{
do_something;
}
catch( e )
{
TheApplication().RaiseErrorText(Clib.rsprintf(
"Something bad happened: %s\n",e.toString()));
}
The finally clause includes code that Siebel eScript must run before it exits the Try statement, regardless of if a catch clause stops running the script. You can write code that uses one of the following statements to exit a finally clause:
Goto
Throw
Return
The following example includes a finally clause. Siebel eScript continues running this code after the no_way statement. It ignores the Return statement:
try
{
return 10;
}
finally
{
goto no_way;
}
no_way: statement_block