Copyright © 2024 Sebastiaan Heins
catch is an extension.
catch is used to catch errors.
catch is followed by a block of code.
If an error occurs in the previous block of code, the error is caught and the block of code is executed. It prevents the program from crashing
Catch encapsulates everything before it, so it can be used to catch errors in a larger block of code.
Example of a catch statement:
do {
do say (notDefined) // Error is thrown
} catch {
do say ("An error occurred") // Error is caught
do say ("The code: " + _) // The code is stored in the _ variable
}