Error

In the current release, error definitions are not used in JSL. However, the Java API can use error definitions.

An error is an event that occurs during the execution of an application. If an error occurs within the application, it interrupts the normal process of program instructions, and the application must create an error description object to pass it to the external caller.

Error descriptors can only contain fields of domain primitive type. Errors are usually kept simple, often only offering a few number of fields that allow information about the error to be extracted by handlers for the error.

To define an error, use the error keyword.

Syntax:

error <name> {
    [field] ...
}

where the <name> is the name of the error, and the error fields are defined between { and }.

Example:

error GenericError {
}

The example above defines an error named GenericError. This error has no fields.

An error may contain data descriptions called fields. A field has an associated domain type that must be a domain model primitive. Fields cannot store multiple primitive values (that is, lists, sets), but only a single primitive value.

Use the field keyword to specify a field within an error.

Syntax:

field <primitive> <name> [default:<default>];

where <primitive> is the name of a domain model primitive, and <name> is the referable name of the field.

Optionally, a <default> value can be specified as an expression. The <default> value expression is evaluated when a new instance of the error is created, and the field is set according to the default value expression. See [Expression] later.

The self variable cannot be used in default expressions.

Example:

error PersonNotFound {
    field String email;
}

The example above defines an error named PersonNotFound. This error has only one field. email is a string that contains an email address that doesn’t match any person’s email address.