Category:Smalltalk: Difference between revisions
Content added Content deleted
Line 441: | Line 441: | ||
<lang smalltalk>[ try block to be evaluated ] on: exception do:[:ex | handler code ]</lang> |
<lang smalltalk>[ try block to be evaluated ] on: exception do:[:ex | handler code ]</lang> |
||
the 'ex' argument to the hander provides detail information (where and why) and also allows control of how to |
the 'ex' argument to the hander provides detail information (where and why) and also allows control of how to continue after the handler (proceed, return, restart, reject). |
||
The handler basically has the following options: |
<br>The handler basically has the following options: |
||
* ex return - return out of the try block |
* ex return - return out of the try block |
||
* ex restart - restart the try block |
* ex restart - restart the try block |
||
Line 448: | Line 448: | ||
* ex proceedWith: value - proceed after where the exception was raised (after a repair) |
* ex proceedWith: value - proceed after where the exception was raised (after a repair) |
||
Exceptions may be specified to be nonProceedable, to protect code from proceeding handlers, where proceeding is not possible. |
Exceptions may be specified to be nonProceedable, to protect code from proceeding handlers, where proceeding is not possible. |
||
Exceptions form a hierarchy, so a handler will also catch any derived exceptions. If an exception is unhandled, the original exception info is packed up and an UnhandledException is raised |
Exceptions form a hierarchy, so a handler will also catch any derived exceptions. If an exception is unhandled, the original exception info is packed up and an UnhandledException is raised (similar to the handling of doesNotUnderstand:). The default handler for UnhandledException opens a debugger for the misbehaving thread (while usually other threads continue to operate as usual). |
||
Handlers can also be defined to handle a collection of non-related exceptions, by creating an exceptionSet: |
Handlers can also be defined to handle a collection of non-related exceptions, by creating an exceptionSet: |