Error Handling
An overview of error handling and debugging in Stof.
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).
The "throw" function is located in the Standard Library and the Try-Catch statement can be referenced in the Stof Language Reference page.
Library Error
Throw Custom Error
Debugging
The "trace" & "callstack" functions can be found in the Standard Library.
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.
Last updated