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 produced by throw or by null function parameters which must not be null without interrupting the execution, use the try-catch statement block on the code which might cause an exception:

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

If the catch statement takes null, any error is caught.

Note: To get the error code and message of the error, use the getErrorCode() and getErrorMessage() functions in the catch:

try 
  createModelInstance(
    synchronous -> true,
    model -> getModel("childProcess","1.0"),
    properties-> ["Triggered by" -> thisModelInstance().id.toString()]
  )
  catch null, "error" -> log("Error: " + getErrorCode() + getErrorMessage(), ERROR_LEVEL)
end

Example:

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

Example: Catching any error code

try executeFunction()
  catch null -> "Code value is not valid."
end

Note that the block returns an object, which you can cast 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)
AmbiguousNameError The provided name cannot be resolved to a unique entity.
ArithmeticError An operand in an arithmetic operation cannot be processed.
BinaryDataError Binary data cannot be retrieved (for example, from database).
DoesNotExistError The entity does not exist.
FormatError The format of an argument is incorrect (for example, on casting of a String).
IncompatibleTypeError The type of processed value is incorrect (typically on casting or assigning).
IncorrectPathname The string with the path in invalid.
MergeEvaluationError Evaluation context created by a View Model cannot be merged.
ModelInstantiationError Instantiation of a model failed.
ModelInterpretationErrorModel cannot be interpreted.
NoExternalRecordProviderThe resource with the requested external record is not available.
NoSuchPropertyError The record property does not exist.
NullParameterError A mandatory parameter has the null value.
OutOfBoundsError The collection element does not exist.
OptimisticLockConflictExceptionSaving changes to record instance failed since the underlying versioned record instance was changed.
ReadOnlyAccessError The system attempted to write to a read-only object.
RecordNotFound The record instance does not exist.
ReferenceNotFound Dereferencing failure (Referenced value was not found.)
SendingError Error sending failed.
SendingSignalError Signal sending failed.
WrongSizeError* The size of a value is incorrect (for example, a String being cast to a map).