Start of Content Area

This graphic is explained in the accompanying text Exception Listener  Locate the document in its SAP Library structure

Whenever errors occur, the 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.

To define a Listener, create a class that implements the JCO.ServerExceptionListener and JCO.ServerStateChangedListener:

Syntax

public class MyExceptionAndErrorListener

implements JCO.ServerExceptionListener, JCO.ServerErrorListener {

 

  public void serverExceptionOccurred(JCO.Server server, Exception ex)

  {

    System.out.println("Exception in server " + server.getProgID() + ":\n" + ex);

    ex.printStackTrace();

  }

  public void serverErrorOccurred(JCO.Server server, Error er)

  {

    System.out.println("Error in server " + server.getProgID() + ":\n" + er);

    er.printStackTrace();

  }

}

 

Register the Listener class with JCO.addServerErrorListener and JCO.addServerExceptionListener:

Syntax 

public class SecondExample extends FirstExample {

    public static void main(String[] args) {

        MyExceptionAndErrorListener l = new MyExceptionAndErrorListener();

        JCO.addServerErrorListener(l);

        JCO.addServerExceptionListener(l);

        FirstExample.startServers() ;

    }

}

 

 

 

End of Content Area