Difference between revisions of "Using the Provided try() Exception Handler"
m (Created page with "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 ...") |
m |
||
Line 1: | Line 1: | ||
− | 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. | + | 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 [http://www.easyuo.com/openeuo/wiki/index.php/Changing_Default_Error_Reporting_Mode 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 [[clearerrors]]. | To understand the available reporting and redirection modes, see the page on [http://www.easyuo.com/openeuo/wiki/index.php/Changing_Default_Error_Reporting_Mode 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 [[clearerrors]]. | ||
[[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. | [[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 == | ||
+ | |||
+ | * [[error]] | ||
+ | |||
+ | * [[pcall]] | ||
+ | |||
+ | * [[clearerrors]] | ||
+ | |||
+ | * [[geterror]] | ||
+ | |||
+ | * [[try]] |
Revision as of 22:10, 1 November 2010
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 clearerrors.
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.