Exceptions
exceptions and error handling
Functions
Predicates
Constants
The Exceptions module provides error handling functionality and predefined error types. It enables robust error management and graceful failure handling in your applications.
Important
The error handling system in Arturo is still evolving. The functionality described in this module should be considered transitional and may change in future versions as the error handling system matures.
Key Concepts
- Error throwing and catching
- Predefined error types
- Error assertions
- Error testing capabilities
Basic Usage
Error Handling
; basic try-catch pattern
if error? err: <= try [
; some risky operation
result: 10 / 0
][
print "something went wrong!"
print err
]
Throwing Errors
; throw generic error
throw "Something went wrong"
; throw with specific error type
throw.as:valueError "Invalid input provided"
; throw with custom message
throw "User not found: %id=123"
Error Testing
; test if operation throws an error
if throws? [
10 / 0
] -> print "Operation has thrown an error"
Predefined Error Types
; available error types
nameError ; when symbol not found
typeError ; when type mismatch
valueError ; when value is invalid
arithmeticError ; for math operations
indexError ; for invalid indices
syntaxError ; for parsing issues
systemError ; for OS-related errors
runtimeError ; for general runtime issues