Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes try-catch-final and throw new Exception cert question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "try-catch-final and throw new Exception cert question" Watch "try-catch-final and throw new Exception cert question" New topic
Author

try-catch-final and throw new Exception cert question

Otto Deckelman
Ranch Hand

Joined: Mar 28, 2001
Posts: 30
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

Joined: Nov 10, 2000
Posts: 165
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: try-catch-final and throw new Exception cert question
 
Similar Threads
Order of execution
Loop with throw ...
Jammi Question
try/catch cert guide quiz question???
try catch finally