This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes OOP-2 Exception question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "OOP-2 Exception question" Watch "OOP-2 Exception question" New topic

OOP-2 Exception question

Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
I'm having a problem with Exception handling in OOP-2. I have a method that throws an Exception, and I am creating the Exception with a String. The Catch block is trying to use the getMessage() method, but it is reporting as NULL.
Any ideas?
Sorry I didn't post any code, don't want to go too far...

Wait a minute, I'm trying to think of something clever to say...<p>Joel
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
That's a hard one to help out on without seeing the actual code. I'm assuming the following:
Your method has the appropriate throws statement.
Your method has a test that may throw new Exception...
What exactly are you putting into your String? If you are passing it a variable of some sort, is it possible that the String is not getting initialized, and that is where the problem is, instead of your exception handling?
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Also, make sure you are catching the right Exception. Depending on how you structured your try/catch block, you might be getting some other exception, and hence, no message is being created, so you see null.
For instance, if what you are really getting is an ArrayIndexOutOfBoundsException somewhere, and you have catch( Exception e ), you could be catching it instead.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9044
Maybe you could test for null in the method. Then you could throw the exception if ( whatever == null ) is true.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
jQuery in Action, 2nd edition
subject: OOP-2 Exception question
Similar Threads
OOP-2 : NaturalLanguageMultiply
Practical example for Abstraction
how do I fix compiler warning: unchecked conversion