Exceptions
The standard library provides the type core.Exception
, which is the root class for all exceptions
in Storm. Each exception contains a message, and optionally also a stack trace. It has the
following members:
-
core.Str message()
Retrieve the message in the exception. This function simply calls
message(StrBuf)
to generate the message. -
void message(core.StrBuf to)
Create the message by appending it to the string buffer.
-
core.StackTrace stackTrace
Collected stack trace, if any.
-
core.Exception saveTrace()
Convenience function to call to collect a stack trace. Intended to be called from the constructor of derived exceptions who wish to store a stack trace. This is not done by default, as it is fairly expensive, and not beneficial for all exceptions (e.g. syntax errors). Some categories of exceptions do, however, capture stack traces automatically. Returns
this
to allow chaining it after creation.
The saveTrace
function returns the exception itself. This makes it convenient to add a stack trace
to an exception temporarily by modifying code like:
throw MyException();
into:
throw MyException().saveTrace();
Exception Categories
The following exceptions are provided in the standard library:
-
core.RuntimeError
extendsException
Depicts a runtime error from some part of the system. The following subclasses are provided:
-
core.GcError
extendsRuntimeError
Thrown when the garbage collector detects an issue. Typically when available memory is low.
-
core.NumericError
extendsRuntimeError
Thrown when a numeric operation failed.
-
core.DivisionByZero
extendsNumericError
Thrown whenever division by zero is attempted.
-
-
core.MemoryAccessError
extendsRuntimeError
Thrown when an invalid memory address was accessed.
-
core.InternalError
extendsRuntimeError
Generic form of internal error.
-
core.AbstractFnCalled
extendsRuntimeError
Thrown when an abstract function was called.
-
-
core.NotSupported
extendsException
Thrown when an operation is not supported.
-
core.UsageError
extendsException
Thrown when an interface is used incorrectly.
-
core.StrError
extendsException
Errors from
core.Str
. -
core.MapError
extendsException
Errors from
core.Map
andcore.RefMap
. -
core.SetError
extendsException
Errors from
core.Set
andcore.RefSet
. -
core.ArrayError
extendsException
Errors from
core.Array
.