• Advertisement
Sign in to follow this  

[java] Java Exception Handling

This topic is 4928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having trouble catching an exception. How do you catch RuntimeExcpetions like StringIndexOutOfBounds - I've tried this but it does'nt work.
try
{
    retVal = invokeMethod();
}
catch(Exception1 e)
{
   // handle it
}
catch(StringIndexOurOfBounds e2)
{
   // handle it
}
The problem is that I get a compile error that reVal isint initialized (I dont get that if I remove the second catch block), and the method docuementation says it throws only Exception1. But occasionally I get the RuntimeException::StringIndexOutOfBounds. How do I handle this ?? thanks

Share this post


Link to post
Share on other sites
Advertisement
Also, you should catch the StringIndexOurOfBounds first, because all exceptions are of type Exception, so it would be caught in the first catch block.

Share this post


Link to post
Share on other sites
Touche.

I didn't even notice the 1. So in that case, if the 1 was intentional, disregard what I said (well, only disregard it if you already knew it).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement