Skip to content

Error Rt

Spice
import "std/runtime/error_rt";

Error struct

This is the generalized error type in Spice and part of the error handling mechanism.

Constructors

ctor

Spice
public p Error.ctor()

Construct a generic error with code 0 and a default message

ctor

Spice
public p Error.ctor(ErrorCode errorCode, string message)

Construct an error with the given code and message

Parameters

Name Type Description
errorCode ErrorCode Error code
message string Error message

ctor

Spice
public p Error.ctor(string message)

Construct an error with the given message and code 1

Parameters

Name Type Description
message string Error message

Methods

getCode

Spice
public inline f<ErrorCode> Error.getCode()

Retrieve error code

Returns: ErrorCode — Error message

getMessage

Spice
public inline f<string> Error.getMessage()

Retrieve error message as immutable string

Returns: string — Error message

isOk

Spice
public inline f<bool> Error.isOk()

Check if the error is set to the default error code 0, which means ok / no error

Returns: bool — Is set to error code 0

print

Spice
public inline p Error.print()

Prints the error message to the console.

triggerPanic

Spice
public inline p Error.triggerPanic()

Panic with this error

dumpTrace

Spice
public inline p Error.dumpTrace()

Prints the error message and the recorded error return trace to stderr. A no-op if no trace was ever recorded, which is always the case unless #![core.compiler.errorReturnTracing = true] was set somewhere along the propagation chain - so this is always safe to call regardless of that attribute's state.

ErrorCode enum

Item Value Description
Ok 0
RuntimeError 1