• Post Reply Bookmark Topic Watch Topic
  • New Topic

A specific Exception inside one class returns a different exception inside it's calling Class.  RSS feed

 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose we have two java classes A & B. A class calls a method in B(this method does not return any value).A specific exception occurs inside this method and handled in Catch Block inside this method itself. Now when the control moves on to the next line in Class A , it shows an exception (Null Pointer Exception). There is a difference between these exceptions. I need the Specific Exception to be returned in both the classes. Help me. I have tried getErrorCode() method but it can be used for only Specific Exceptions. For a general Exception block it does not apply. HashCode() is same but it may not be same always.Also i have lots of dependencies on both the classes. So i'm not able to change the code to my requirement. Is there any method i can use to get any of the specific error property to my calling class.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have no way of chaining those exceptions?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem description isn't very clear. But it sounds like there are two components to the question:

(1) Class B isn't doing what you want.

(2) How can you change Class A to fix that?

If that's an accurate interpretation of the question, then wouldn't it be better to just fix Class B to do what you want? Or is that not what you meant to say?

(I notice it's very common for people who name their classes things like "A" and "B" to have trouble describing problems. I think it's something to do with the un-intuitive class names. Perhaps posting code would help.)
 
karthik Suryanarayanan
Ranch Hand
Posts: 121
Java Opera Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much guys. I have tried a bit but as you said i could not chain them. Will provide the Exact Code after sometime for others understanding.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!