Show TOC

Example documentationException Listener Locate this document in the navigation structure

 

Whenever errors occur, JCo throws an exception. All sxceptions that occur in the JCo are passed on to the registered Exception and Error Listener.

Note Note

The application must process the exceptions separately in the method handleRequest()(that is, the exceptions that it generates itself). Exceptions from the application coding are not passed on to the Listener.

End of the note.

JCO.ServerExceptionListener and JCO.ServerStateChangedListener:

JCO.ServerExceptionListener and JCO.ServerStateChangedListener:

Syntax Syntax

  1. public class MyExceptionAndErrorListener 
  2. implements JCO.ServerExceptionListener, JCO.ServerErrorListener {
  3.   public void serverExceptionOccurred(JCO.Server server, Exception ex)
  4.   {
  5.     System.out.println("Exception in server " + server.getProgID() + ":\n" + ex);
  6.     ex.printStackTrace();
  7.   }
  8.   public void serverErrorOccurred(JCO.Server server, Error er)
  9.   {
  10.     System.out.println("Error in server " + server.getProgID() + ":\n" + er);
  11.     er.printStackTrace();
  12.   }
  13. }
End of the code.

Register the Listener class with JCO.addServerErrorListener and

JCO.addServerExceptionListener:

Syntax Syntax

  1. public class SecondExample extends FirstExample {
  2.     public static void main(String[] args) {
  3.         MyExceptionAndErrorListener l = new MyExceptionAndErrorListener();
  4.         JCO.addServerErrorListener(l);
  5.         JCO.addServerExceptionListener(l);
  6.         FirstExample.startServers() ;
  7.     }
  8. }
End of the code.