Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can't use RemoteException.getCause() instanceof MyException !!

843829Sep 8 2002 — edited Aug 1 2003
Hi there, please help me out on this one, I just can't figure out the problem!

I have a swing client and a Session EJB that will throw a DataNotFoundException (subclass of EJBException) if the supplied id was not found in the database:
And as the EJBException is a RuntimeException, it will be autowrapped in RemoteException by the EJB container. Now, on the client we use RemoteException.getCause() to get this DataNotFoundException. getCause returns a Throwable (highest in hierarchy). Now, shouldn't I be able to use instanceof DataNotFoundException?? I mean, it is indeed an exception of this type! But the comparison gives FALSE! However, using (...instanceof Throwable) gives TRUE, as does comparing with Exception!

Anyone knows why I don't get true on (re.getCause() instanceof DataNotFoundException) ??

I'd be very pleased if someone knows the answer!!

Best regards,
AC
(I posted this question on SUN/java language forum too, but got no answers yet!)


try{
filmEJB.insertOrder(orderVO,number);
}catch(RemoteException re){
if (re.getCause() instanceof DataNotFoundException)//returns false!!!
System.out.println("CAUGHT DataNotFoundException");
re.printStackTrace();

//etc, etc
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2003
Added on Sep 8 2002
1 comment
687 views