LSPS documentation logo
LSPS Documentation
Exception Handling

On runtime, code can cause an error that halts the execution and potentially terminate the execution unexpectedly. Typically, this can occur on user input, when the user input is unexpected (for example, while the code expects a Decimal value and the user enters a value with letters). Exception handling enables you to deal with such situations and handle the thrown exception gracefully.

To handle an exception, use the try-catch construct on the code.

Also, you can decide that a particular expression should produce an exception. To throw an exception, use the error() function from the Standard Library.

Throwing Exceptions

The error() function throws an error with an error code. The error code is a String parameter of the construct.

error(<errorcode>)

Example:

error("InvalidISBNFormat")

If an error exception is not caught and handled, the execution terminates. The error can be caught and handled by a try-catch block.

Important: Error throwing functions are part of the Standard Library. Refer to the Standard Library Reference for further information.

Catching Exceptions

To catch and handle error exceptions without interrupting the execution, use the try-catch block on the code which might cause an exception:

try <expression>
    catch <error_code>, ... -> <handle_expression_1>;
    handle_expression_2;
    ...
end

Example:

try getCode()
  catch "Invalid ISBN format", "Invalid ISSN format" -> "Code value is not valid."
end

If catch takes null, any error is caught. Note that the block returns an object and you might need to cast it as appropriate:

try val.toDecimal()
catch null -> "not decimal" as String

Built-in Errors

The Expression Language makes use of the errors with the following error codes:

Error Description (occurrence circumstances)
*NullParameterError* A mandatory parameter has the null value.
*IncompatibleTypeError* The type of processed value is incorrect (typically on casting or assigning).
*ArithmeticError* An operand in an arithmetic operation cannot be processed.
*OutOfBoundsError* The collection element does not exist.
*FormatError* The format of an argument is incorrect (for example, on casting of a String).
*WrongSizeError* The size of a value is incorrect (for example, a String being cast to a map).
*NoSuchPropertyError* The record property does not exist.
*DoesNotExistError* The entity does not exist.
*RecordNotFound* The record instance does not exist.
*ReferenceNotFound* Dereferencing failure (Referenced value was not found.)
*ModelInstantiationError* Instantiation of a model failed.
*ModelInterpretationError*Model cannot be interpreted.
*SendingError* Error sending failed.
*SendingSignalError* Signal sending failed.
*MergeEvaluationError* Evaluation context cannot be merged (refer to Forms User Guide).
*BinaryDataError* Binary data cannot be retrieved (for example, from database).
*ReadOnlyAccessError* The system attempted to write to a read-only object.
*IncorrectPathname* The string with the path in invalid.
*NoExternalRecordProvider*The resource with the requested external record is not available.
*AmbiguousNameError* The provided name cannot be resolved to a unique entity.