Home Tutorial Java Scjp Part6 SCJP Module-6 Question-17


Share on Google+Share on Google+
SCJP Module-6 Question-17
Posted on: July 14, 2010 at 12:00 AM
The sample program given below will check your understanding about the Exception and their Handling Java. It is very helpful for successful completion of SCJP examination.

Given below the sample code :

1 public class A {
2 static void test() throws Error{
3 if (true) throw new AssertionError();
4 System.out.print("test ");
5 }
6 public static void main(String[] args) {
7 try { test(); }
8 catch (Exception ex) { System.out.print("exception "); }
9 System.out.print("end ");

How can we correct the above code ?

1. No need of correction

2. By changing "Exception" class to "Error" at line 8 in "caught"

3. By changing "throws Error" to "throws Exception" at line number 2.

4. By throwing exception in place of error at line 2.

Answer :


Explanation :

Above code will give uncaught exception as output. Since it is of type "error " so it should be handled by error class object.


Related Tags for SCJP Module-6 Question-17:

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.

Posted on: July 14, 2010

Recommend the tutorial

Advertisements Advertisements