Ultra Light Client Guide and Reference

Implementing custom exception handling

To customize exception handling, implement a class method called #exceptionHandlerForContext: aUlcContext in the ULC startup class for your application. This class is typically a subclass of UlcAppBldrView. At run time, the active context sends this message to the startup class before an instance of the class is created.

MyAppBldrViewStartupClass class>>#exceptionHandlerFor: aUlcContext
   "answer the custom exception handler for this application"
 
   ^MyCustomExceptionHandlerClass new context: aUlcContext; yourself

If the receiver of the message answers nil, default exception handling is installed on the current process. Any other object answered is expected to have implemented the #catchExceptionsWhile: aBlock method. The aBlock parameter represents the exception-handling code to be run.

MyCustomExceptionHandlerClassOne>>#catchExceptionsWhile: aBlock
   "Install the custom exception handlers on aBlock. 
    Terminate the receiver's context in all cases"
 
   ^aBlock
       when: ExError
       do: [:signal|self closeApplicationLog. 
              "performing some application specific tasks"
               UlcDebugger errorMessage: self someApplicationSpecificErrorMessage.
               [self context terminate] forkNamed: 'terminating context after error'
           ]

If default handling suffices for now, you can replace the last two lines of the handler block with code that invokes default handling, as follows:

MyCustomExceptionHandlerClassTwo>>#catchExceptionsWhile: aBlock
   "Install the custom exception handlers on aBlock. 
    Terminate the receiver's context in all cases"
 
   ^aBlock
       when: ExError
       do: [:signal|self closeApplicationLog. 
              "performing some application specific tasks"
               signal signal "invoking default handling"
           ]

To change the exception handler dynamically, send #setExceptionHandler: anObject to a context or its UlcProcessOwnerToken. anObject must have implemented the #catchExceptionsWhile: aBlock method. anObject can also be nil, which causes exception handling to revert to the default.

In any case, the new exception handler takes effect only on processes spawned after it was set. Any handler already installed on a process is not affected by the change.

To change the error message displayed at run time, edit the message called UlcAlertTerminateContext. You can find the definition for this message in the files UlcWidxxx.tra and UlcWidxxx.mpr.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]