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.
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
(1)