January 2024
Intermediate to advanced
718 pages
20h 15m
English
So far, we’ve been on the defensive, handling exceptions raised by others. It’s time to turn the tables and go on the offensive. It’s time to raise some…exceptions.
You can raise exceptions in your code with the raise method (or its judgmental and less commonly used synonym, fail):
| | raise |
| | raise "bad mp3 encoding" |
| | raise InterfaceException, "Keyboard failure" |
The first form simply reraises the current exception (or raises a RuntimeError if no current exception exists). This is used in exception handlers that intercept an exception before passing it on.
The second form creates a new RuntimeError exception, setting its message to the given string. This exception is then raised up the call stack.
The third form uses ...
Read now
Unlock full access