• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OOP-2 Exception question

 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Jason
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could test for null in the method. Then you could throw the exception if ( whatever == null ) is true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic