Anonymous user
Exceptions: Difference between revisions
Add some examples of Factor exceptions
(→try-except-finally-else: clarify) |
(Add some examples of Factor exceptions) |
||
Line 98:
}
}
=={{header|Factor}}==
===Throw Exceptions===
"Install Linux, Problem Solved" throw
TUPLE: velociraptor ;
\ velociraptor construct-empty throw
===Catch Exceptions===
! Preferred exception handling
: try-foo
[ foo ] [ foo-failed ] recover ;
: try-bar
[ bar ] [ bar-errored ] [ bar-always ] cleanup ;
! Used rarely
[ "Fail" throw ] try ! throws a "Fail"
[ "Fail" throw ] catch ! returns "Fail"
[ "Hi" print ] catch ! returns f (looks the same as throwing f; don't throw f)
[ f throw ] catch ! returns f, bad! use recover or cleanup instead
=={{header|Forth}}==
Forth's exception mechanism is, like most things in Forth, very simple but powerful.
|