Wrapping and Re-throwing Errors
Add context as errors travel up.
Errors Travel Upward
When a function cannot handle a failure itself, it passes the error to its caller. Along the way you can adjust or re-throw it.
Re-throw with try
The simplest re-throw is try. It forwards the original error unchanged to your caller, so the same value keeps bubbling up.
const data = try readFile(path);All lessons in this course
- Recover with catch
- Switch on Specific Errors
- errdefer for Failure Cleanup
- Wrapping and Re-throwing Errors