The great news for me that there are possibility to throw any type of exception in EJB's methods.
For example:
public class MyException extends Exception {
public MyException(String mess)
{ super(mess); }
}
So my EJB method might be:
@RemoteMethod public String someMethod(String param) throws MyException {
throw new MyException("Text");
}
Also client have to catch it. Pay attention that now stack trace will look like:
Exception in thread "main" com.epam.ejb.MyException: Test..
not the same as in case of throwing RuntimeException :
Exception in thread "main" java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.RuntimeException: Text..
Another interesting fact is understanding about exception chaining:
Exception e = new Exception();
if( e.getCause() instanceof MyException) { }
For example:
public class MyException extends Exception {
public MyException(String mess)
{ super(mess); }
}
So my EJB method might be:
@RemoteMethod public String someMethod(String param) throws MyException {
throw new MyException("Text");
}
Also client have to catch it. Pay attention that now stack trace will look like:
Exception in thread "main" com.epam.ejb.MyException: Test..
not the same as in case of throwing RuntimeException :
Exception in thread "main" java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.RuntimeException: Text..
Another interesting fact is understanding about exception chaining:
Exception e = new Exception();
if( e.getCause() instanceof MyException) { }
No comments:
Post a Comment