public static NamingException wrapRemoteException(RemoteException re){
  NamingException ne;
  if (re instanceof ConnectException) {
    ne=new ServiceUnavailableException();
  }
 else   if (re instanceof AccessException) {
    ne=new NoPermissionException();
  }
 else   if (re instanceof StubNotFoundException || re instanceof UnknownHostException || re instanceof SocketSecurityException) {
    ne=new ConfigurationException();
  }
 else   if (re instanceof ExportException || re instanceof ConnectIOException || re instanceof MarshalException|| re instanceof UnmarshalException|| re instanceof NoSuchObjectException) {
    ne=new CommunicationException();
  }
 else   if (re instanceof ServerException && re.detail instanceof RemoteException) {
    ne=wrapRemoteException((RemoteException)re.detail);
  }
 else {
    ne=new NamingException();
  }
  ne.setRootCause(re);
  return ne;
}

public static NamingException wrapRemoteException ( RemoteException re ) { NamingException ne ; if ( re instanceof ConnectException ) { ne = new ServiceUnavailableException ( ) ; } else if ( re instanceof AccessException ) { ne = new NoPermissionException ( ) ; } else if ( re instanceof StubNotFoundException || re instanceof UnknownHostException || re instanceof SocketSecurityException ) { ne = new ConfigurationException ( ) ; } else if ( re instanceof ExportException || re instanceof ConnectIOException || re instanceof MarshalException || re instanceof UnmarshalException || re instanceof NoSuchObjectException ) { ne = new CommunicationException ( ) ; } else if ( re instanceof ServerException && re . detail instanceof RemoteException ) { ne = wrapRemoteException ( ( RemoteException ) re . detail ) ; } else { ne = new NamingException ( ) ; } ne . setRootCause ( re ) ; return ne ; }
wrap a remoteexception inside a namingexception .
