Listing 6. Here is an example of the handling of a service-specific exception, first showing the MyException implementation, then showing the Web service back-end component.

public class MyException extends Exception {
   private String errorMessage;
   private int errorId;

   //public MyException();
   public MyException(String errorMessage, 
      int errorId) {
      this.errorMessage = errorMessage;
      this.errorId = errorId;
   }

   public void setErrorMessage(String errorMessage) 
      { this.errorMessage = errorMessage; }
   public String getErrorMessage() 
      { return errorMessage; }

   public void setErrorId(int errorId) 
      { this.errorId = errorId; }
   public int getErrorId() { return errorId; }
}

import javax.xml.soap.SOAPFactory;
import javax.xml.soap.Detail;
import javax.xml.soap.SOAPException;

import javax.xml.namespace.QName;
import javax.xml.rpc.soap.SOAPFaultException;

public final class HelloWorld {
   public void sendSOAPFault()throws MyException 
   {
      throw new MyException("sendSOAPFault() call 
         fails !", 10);
   }
}