• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try-catch-final and throw new Exception cert question

 
Otto Deckelman
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question in my Java cert study guide book. I do not understand what statement will catch the 'E1' exception.
What lines of output are displayed by the following program?
class Question {
public static void main(String[] args) {
for(int i=0;i<10;++i) {
try {
try {
if(i % 3 == 0) throw new Exception("E0");
System.out.println(i);
}catch (Exception inner) {
i *= 2;
if(i % 3 == 0) throw new Exception("E1");
}finally{
++1;
}
}catch (Exception outer) {
i += 3;
}finally{
--1;
}
}
}
}
 
Brian Lugo
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This statement will catch E1 exception:
}catch (Exception outer) {
Its a nested try-catch-finally block.
E1 is thrown from the inner block and will be caught by the outer try block.
Brian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic