Computer Science, asked by viru832, 9 months ago

Predict the output of following Java program
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception
+ e);
}
}
}
O Got the Exception 10
Got the Exception 0
O Compiler Error
O None of the above​

Answers

Answered by VedankMishra
4

Ans. (d)

Explanation: Once an exception occurs in try block, the execution passes to corresponding catch statement and doesn’t return back to try block. Only one of the catch blocks are executed at a time. finally block is always executed whether or not the exception occurred.

Answered by durgeshbishi2
0

Answer: Compiler Error

Explanation:

class Main {

public static void main(String args[]) {

try {

 throw 10;

}

catch(int e) {

 System.out.println("Got the Exception " + e);

}

}

}

As the output of the following given code is Compile Error,

incompatible types: int cannot be converted to Throwable

 throw 10;

 ^

unexpected type

catchint e) {

      ^

 required: class

 found:    int

So 2 errors were found.

#SPJ3

Similar questions