Try…Catch…End Statement (FPScript)
Catches exceptions that occur in the statements included and enables their processing.
Syntax
Try
[TryStatements]
Catch Variable
[CatchStatements]
End
The syntax of the Try...Catch...End statement consists of the following elements:
Element |
Description |
---|---|
TryStatements |
One or more statements between Try and Catch for which occurring exceptions are to be caught. |
Variable |
Name of a variable to which the value of the exception is assigned. You do not have to declare the variables with Dim. |
CatchStatements |
One or more statements for handling the exceptions that have been caught. |
Remarks
Exceptions are all errors that may occur during the execution of FPScript code as well as exceptions that have been explicitly generated using the Throw statement.
If an exception occurs while a formula is being calculated, this calculation usually stops and an error message is generated. With the Try...Catch statement, however, you can catch these types of exceptions and handle them appropriately. This does not just work within one formula but also if the exception occurs in another formula, which is called by the formula with the Try...Catch statement.
An exception always has a value. If an error occurs during execution, the value of the exception generated is a string with the error message. If an exception is generated with the Throw statement, any value, including a unit, if applicable, can be supplied that can then be processed in the Catch block.
Within the Catch block, you can process certain exceptions depending on their value and pass others on using the Throw statement.
Note: You should use exception handling only for exceptional circumstances and not as an alternative to the Return statement.
Available in
FlexPro View, Basic, Professional, Developer Suite
Example
Calculates an integral and returns the result. If an error occurs during integration, this is caught and the error message is returned.
Try
Return Integral(x)
Catch Exception
Return Exception
End