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
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.
JCO.ServerExceptionListener and JCO.ServerStateChangedListener:
JCoServerExceptionListener and JCoServerErrorListener implements:
Syntax
static class MyThrowableListener implements JCoServerErrorListener, JCoServerExceptionListener
{
public void serverErrorOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Error error)
{
System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
error.printStackTrace();
}
public void serverExceptionOccurred(JCoServer jcoServer, String connectionId, JCoServerContextInfo serverCtx, Exception error)
{
System.out.println(">>> Error occured on " + jcoServer.getProgramID() + " connection " + connectionId);
error.printStackTrace();
}
}
Register the listener class with server.addServerErrorListener and
server.addServerExceptionListener:
Syntax
MyThrowableListener eListener = new MyThrowableListener();
server.addServerErrorListener(eListener);
server.addServerExceptionListener(eListener);