Skip to content
Related Articles

Related Articles

Java | Exception Handling | Question 1

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 08 Jul, 2021

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);

(A) Got the Exception 10
(B) Got the Exception 0
(C) Compiler Error

Answer: (C)

Explanation: In Java only throwable objects (Throwable objects are instances of any subclass of the Throwable class) can be thrown as exception. So basic data type cannot be thrown at all.

Following are errors in the above program error: incompatible types
         throw 10;
  required: Throwable
  found:    int error: unexpected type
      catch(int e) {
  required: class
  found:    int
2 errors

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!