Skip to content

Error Rt Freestanding

Spice
import "std/runtime/error_rt_freestanding";

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 code

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

dumpTrace

Spice
public inline p Error.dumpTrace()

Prints the error message and the recorded error return trace. There is no stderr in freestanding mode and error return tracing is disabled, so this does nothing. It exists, so that code calling it compiles in both modes.

triggerPanic

Spice
public inline p Error.triggerPanic()

Panic with this error

ErrorCode enum

Item Value Description
Ok 0
RuntimeError 1