This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
 
 
subject: try-catch-final and throw new Exception cert question
 
Similar Threads
try/catch cert guide quiz question???
Jammi Question
Loop with throw ...
Order of execution
try catch finally