Throw & Throws Keyword in Java

Java throw and throws

The key distinctions between throw and throws are as follows.

Java throws:

 

Example:


When you run this program, it will output:

I Love Java

Example:


When you run this program, it will output:

You should n’t divide number by zero

Java throw:

 

Example :


When you run this program, it will output:

Caught inside fun().

Caught in main

 

 

Visited 1 times, 1 visit(s) today

Comments are closed.

Close