Using the Provided try() Exception Handler

From OpenEUO
Revision as of 06:46, 3 November 2010 by 76.184.213.234 (Talk) (See Also)

Jump to: navigation, search

The try library method is provided as a integrated replacement for pcall which reports and redirects error handling in the same fashion as the library itself. Use try to wrap complex user functions wherever it is desirable to unify error reporting and or maintain script execution by silencing runtime errors that would otherwise halt the script.

To understand the available reporting and redirection modes, see the page on changing the default error reporting and handling mode. To set a specific mode, see slredirect. To understand what information is recorded with each detected error, see geterror. To clear all errors recorded internally and garbage collect, see clrerrors.

try should be used at an appropriately high level in user code such that handler functions don't clutter the source and aren't nested to any degree. try isn't intended to be used low level, either directly on library calls or as a method of program flow micromanagement. Save the error function for throwing bona fide exceptions to the current course of execution; don't use try as a sort of if then statement. If you need C style switch case or a deep elseif alternative, see the case library method.

See Also