Skip to content
Advertisement

Exception thrown inside catch block – will it be caught again?

This may seem like a programming 101 question and I had thought I knew the answer but now find myself needing to double check. In this piece of code below, will the exception thrown in the first catch block then be caught by the general Exception catch block below?

try {
  // Do something
} catch(IOException e) {
  throw new ApplicationException("Problem connecting to server");
} catch(Exception e) {
  // Will the ApplicationException be caught here?
}

I always thought the answer would be no, but now I have some odd behaviour that could be caused by this. The answer is probably the same for most languages but I’m working in Java.

Advertisement

Answer

No, since the new throw is not in the try block directly.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement