| << Previous | Suneido > Contents > Language | Next >> |
try
statement1
[ catch [ ( variable [ , pattern ] ) ]
statement2 ]
throw string
Within the try statement and any functions called by it (directly or indirectly), a throw will cause an immediate transfer of control to the most recent catch statement whose prefix matches the exception. If no prefix is specified, the catch will match all exceptions.
throw may be used within the catch statement to pass the exception to the next catch.
Note: Suneido also generates exceptions internally for things like uninitialized variables and syntax errors.
An uncaught exception will call a user defined Handler function. The Handler in stldlib will bring up a debugger showing the function calls leading up to the exception. Because errors in windows procedures can make it impossible to close the offending window, the message box includes a Destroy Window button that can be used to destroy the active window.
If a variable name is specified in the catch it will be set to the exception string. For example:
try
throw "oops"
catch (e)
Print(caught: e)
=> caught: oops
A catch with a pattern string will catch any exception that starts with that pattern (has it as a prefix). If the pattern starts with a "*" it will match anywhere in the exception. Multiple patterns may be specified by separating them with "|". For example:
try
MyFunc()
catch (e, "*error|*failure")
...
This would catch exceptions that contained "error" or "failure". Any other exceptions would not be caught.
| << Previous | Suneido > Contents > Language | Next >> |