Error Handling
An overview of error handling and debugging in Stof.
Last updated
Was this helpful?
An overview of error handling and debugging in Stof.
Last updated
Was this helpful?
Errors in Stof can occur for various reasons. One example is attempting to call a function that doesn't exist. Another might be giving unexpected arguments that cannot be coerced into the right types or forgetting to provide required arguments.
It is also common to throw custom errors from within Stof according to how you expect your interfaces to be used.
Errors can be caught with the try-catch statement to be handled properly or continued up the stack. The catch block can optionally take an error parameter, with one of three available error types:
str
- error message only.
(str, str)
- error type, then error message respectfully.
map
- an entry for "type: str", "message: str", and "stack: vec", providing a function stack to where the error occurred (the actual function that threw being the last in the vector).
When an error is thrown in Stof and not handled, it will be printed to the console with its stack information (if using the CLI).
However, it is often nice to programmatically trace the call stack when debugging.
The "trace" & "callstack" functions can be found in the .