0 votes
in JAVA by
What is the output of the following Java program?

  public class Main{  

     public static void main(String []args){  

        try  

        {  

            throw 90;   

        }  

        catch(int e){  

            System.out.println("Caught the exception "+e);  

        }  

              

    }  

}

1 Answer

0 votes
by

Below is the output of above program

Main.java:6: error: incompatible types: int cannot be converted to Throwable

            throw 90; 

            ^

Main.java:8: error: unexpected type

        catch(int e){

              ^

  required: class

  found:    int

2 errors

Explanation

In Java, the throwable objects can only be thrown. If we try to throw an integer object, The compiler will show an error since we can not throw basic data type from a block of code.

Related questions

0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
+3 votes
asked May 13, 2021 in JAVA by rajeshsharma
...