Share on Google+Share on Google+

SCJP Module-2 Question-16

Ads
The program given below checks your knowledge of exception handling in Java and. This program also gives some knowledge that how the try block is used in a Java program.

Find the Outputs of the given below code having nested try blocks :

public class Example16 {
public static void main(String[] args) {
for (int a = 0; a< 10; ++a) {
try {
try {
if (a % 3 == 0)
throw new Exception("Except1");
System.out.println(i);
} catch (Exception inside) {
a *= 2;
if (i % 3 == 0)
throw new Exception("Except2");
} finally {
++a;
}
} catch (Exception outside) {
a += 3;
} finally {
--a;
}
}
}
}

Find the Outputs of the given below code having nested try blocks :

1.   4  5

2.  4

3.  5

4 compile error

Answer :

(1)

 

 

Advertisements

Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement