Managing exceptions

To propagate exceptions between the client and server, the application should handle exceptions like events. In other words, you create a handler that listens for the exception. A notifier broadcasts the occurrence of the exception. For exceptions occurring on the client, use the event manager to broadcast the exceptions. For exceptions occurring on the server, use the ExceptionEvent to notify the client. The ExceptionEvent includes information about the exception. The protocol for sending an exception event to the client is:
EventManager.sendException(DSEException anException)

This causes an exception to be propagated to any client that is interested in this event. ExceptionEvents must be used by any application component on the server to allow any component on the client to be aware of a specific exception.

On the client side, any process that needs to handle this kind of server-side exception event must add a handler to the local event manager, after having registered interest in the remote exception. The APIs for these processes are:

EventManager.registerInterestInRemoteException(CSClient aCSClient)
EventManager.addHandlerForException(Handler aHandler, String aServerTID)

An application that was distributed into components on both the client and the server would follow the process described below to handle on the client side an exception that occurred on the server side:

  1. The exception must be an object that extends java.lang.Throwable. Only this type of object can be thrown (and eventually caught) following standard Java(TM) procedures. In particular, the use of exceptions of type DSEException is recommended, since these are the types expected by the event manager.
  2. The component on the client part of the application registers interest in remote exceptions occurring on the server, by adding a handler that waits for the DSEExceptionEvent event.
  3. The component on the server part of the application can either throw the exception (to be handled by whatever is calling it), propagate the exception to any remote workstation that has registered interest in it, or both, depending on how the exception needs to be managed by the running process.
  4. The C/S Messaging API on the remote workstation receives the event information and communicates with the event manager, which in turn dispatches any handler added for the special remote exception event.
  5. The handler belonging to the client-side application component processes the event, parses the exception, and then performs whatever actions are needed.