Runtime

The functions for working with a virtual machine during script execution are described here.

Types

trace

The trace type is used to store information about the called function and has the following fields:

  • str Path - filename

  • str Entry - current function

  • str Func - called function

  • int Line - the line in the source code

  • int Pos - the position in the line where the function was called

Functions

error(int id, str text, anytype pars...)

The error function throws a custom runtime error.

  • id - the identifier of the error,

  • text - the text of the error,

  • pars - optional parameters. If they are specified, then text must contain an appropriate template

    as in Format function.

error(10, `Error message %{ 10 }`)
error(10, `Error message %d`, 10)

ErrID(error err) int

The ErrID function returns the identifier of the err error. This function can be used inside try-catch statement for error handling.

run {
try {
.....
error(101, `oooops`)
}
catch err {
if ErrID(err) == 101 {
recover
} elif ErrID(err) < 100 {
retry
}
}
}

ErrText(error err) str

The ErrText function returns the text of the err error. This function can be used inside try-catch statement for error handling.

ErrTrace(error err) arr.trace

The ErrTrace function returns the stack of called functions at the moment when the err error occurs. This function can be used inside try-catch statement for error handling.

Trace() arr.trace

The Trace function returns a stack of called functions.