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 stackTraceCollected 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
thisto 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.RuntimeErrorextendsExceptionDepicts a runtime error from some part of the system. The following subclasses are provided:
-
core.GcErrorextendsRuntimeErrorThrown when the garbage collector detects an issue. Typically when available memory is low.
-
core.NumericErrorextendsRuntimeErrorThrown when a numeric operation failed.
-
core.DivisionByZeroextendsNumericErrorThrown whenever division by zero is attempted.
-
-
core.MemoryAccessErrorextendsRuntimeErrorThrown when an invalid memory address was accessed.
-
core.InternalErrorextendsRuntimeErrorGeneric form of internal error.
-
core.AbstractFnCalledextendsRuntimeErrorThrown when an abstract function was called.
-
-
core.NotSupportedextendsExceptionThrown when an operation is not supported.
-
core.UsageErrorextendsExceptionThrown when an interface is used incorrectly.
-
core.StrErrorextendsExceptionErrors from
core.Str. -
core.MapErrorextendsExceptionErrors from
core.Mapandcore.RefMap. -
core.SetErrorextendsExceptionErrors from
core.Setandcore.RefSet. -
core.ArrayErrorextendsExceptionErrors from
core.Array.
