• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OOP-2 Exception question

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic