Exceptions: Difference between revisions

added Ursala
m (→‎{{header|AutoHotkey}}: Minor indentation and casing edit)
(added Ursala)
Line 956:
"f"</pre>
 
=={{header|Ursala}}==
 
In this program fragment, a function named thrower returns the
string 'success' if its argument is non-empty, but otherwise
raises an exception with the diagnostic message 'epic fail'.
(The diagnostic message can also be made to depend on the input.)
<lang Ursala>#import std
 
thrower = ~&?/'success'! -[epic fail]-!%
 
catcher = guard(thrower,---[someone failed]-)</lang>
 
If the exception is not caught, the program terminates immediately and
the diagnostic is written to stderr. Alternatively, a calling function
or any caller thereof can be defined to catch an exception as shown. The
exception handler may inspect and arbitrarily
modify the diagnostic message, but normal execution may not be resumed.
In this example, the exception handler appends some additional
verbiage to the message.
=={{header|V}}==
 
Anonymous user