Exception Class

An Exception is a special type of object that is used to represent an error or exceptional condition that occurs during the execution of a program. Exceptions extend from the Error class. Exceptions are used to handle errors in a way that allows the program to continue running, rather than crashing or terminating unexpectedly. In Stackpress, exceptions are primarily used to handle errors. Serialized exceptions are objects and is useful when interchanging between and objects.
Copy

code

The error code (number). Defaults to .
Copy

end

The end position in the code file where the error occurred.
Copy

errors

A map of sub errors. This is usually for form errors. This is a map of field names to error message.
Copy

start

The start position in the code file where the error occurred.
Copy

type

The type of error. This is usually the Exception class name. For example types like DatabaseException or ServerException can help troubleshooting.
Copy

Exception.for()

Expressive way to create an exception.

Usage

Copy

Example

Copy
Copy

Exception.forErrors()

Expressive way to throw an error given a map of sub-errors. This is usually for form errors.

Usage

Copy

Example

Copy

Exception.forResponse()

Expressive way to throw an error given the response object.

Usage

Copy

Example

Copy

Exception.require()

Requires that the condition is true. Otherwise throws an error.

Usage

Copy

Example

Copy
Copy

Exception.try()

In house syncronous try catch.

Usage

Copy

Example

Copy

Exception.upgrade()

Upgrades an error to an exception

Usage

Copy

Example

Copy

toJSON()

Converts exception to a JSON string

Usage

Copy

Example

Copy

toResponse()

Converts error to Response object

Usage

Copy
The start and end parameters are used to slice the stack trace if available.

Example

Copy

trace()

Returns the stack trace if available.

Usage

Copy
The start and end parameters are used to slice the stack trace if available.

Example

Copy

withCode()

Expressive way to set an error code

Usage

Copy

Example

Copy

withErrors()

Expressive way to add sub-errros

Usage

Copy

Example

Copy

withPosition()

Expressive way to add syntax position

Usage

Copy

Example

Copy