Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getCause().. in checked exception of remote interface method.  RSS feed

 
Om Tejas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this peculiar aspect of ejb recently. Not sure if this is by ejb-design.

My remote interface looks like this:

public interface IGeneric {

pubic void validateData(String data) throws DataValidationException, RemoteException;

}

In the corresponding bean, i wrap a cause while throwing DataValidationException:

if(validationFails) {

throw new DataObjectValidation(new DataLenghtViolationException());

}

However, at the client side, when i try to get the root cause by calling getCause() on DataValidationException, I get DataObjectValidationException, not DataLengthViolationException. I have to do getCause().getCause() in order to get the DataLenghtViolationException..

In normal, java app, getCause() alone is sufficient to get the root cause.
Why does EJB, wraps the exception this way .?, Is this by design ?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's your catch clause on the client side? I guess you are getting a EJBException on the client side which wraps the DataObjectValidation which then wraps DataLenghtViolationException.
 
Om Tejas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the catch clause is


catch (DataObjectValidation dov) {

if(dov.getCause() instanceof DataLengthViolationException) {
/// this never comes here

}
}
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srivastava Gaurav wrote:the catch clause is


catch (DataObjectValidation dov) {

if(dov.getCause() instanceof DataLengthViolationException) {
/// this never comes here

}
}


Does the application actually catch the DataObjectValidation exception? In other words:

catch (DataObjectValidation dov) {
// Does it ever get here?
if (dov.getCause() instanceof DataLengthViolationException) {
...

If the exception is wrapped in a remote exception, my guess is the answer is No.

If you're making a remote call, then you'll need to catch the remote exception thrown by the RMI. Then you can get the cause of that, and process as you were.

 
Om Tejas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yes it does...however, the if-condition fails.

 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the code is catching a DataObjectValidation exception, but it doesn't contain the exception you think should be stuffed in there?

You should start looking at what is in there. Perhaps the remote method is not doing what you think.
Does dov.getCause() return null? If not, can you do a getClass().getName() on what you get from that and see what it is?

Also, you should check that the exception you caught really is a DataObjectValidation, as the code will still catch it even if what you have is a subclass of that type (see what dov.getClass().getName() returns).

By the way, are you sure you want an exception class whose name doesn't end with Exception? That may be confusing to others who look at the code.

Good luck.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!