Show TOC

Example documentationException Listener Locate this document in the navigation structure

 

Whenever errors occur, JCo throws an exception. All exceptions 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:

JCoServerExceptionListener and JCoServerErrorListener implements:

Syntax Syntax

  1. static class MyThrowableListener implements JCoServerErrorListener, JCoServerExceptionListener
  2.     {
  3.         
  4.         public void serverErrorOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Error error)
  5.         {
  6.             System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
  7.             error.printStackTrace();
  8.         }
  9.         
  10.         public void serverExceptionOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Exception error)
  11.         {
  12.             System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
  13.             error.printStackTrace();
  14.         }
  15.     }  
  16.  
End of the code.

Register the listener class with server.addServerErrorListener and

server.addServerExceptionListener:

Syntax Syntax

  1. MyThrowableListener eListener = new MyThrowableListener();
  2.         server.addServerErrorListener(eListener);
  3.         server.addServerExceptionListener(eListener);
  4.  
End of the code.