0% found this document useful (0 votes)
2 views

Difference Between Throw and Throws in Java

Java

Uploaded by

Sahil Mali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Difference Between Throw and Throws in Java

Java

Uploaded by

Sahil Mali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Difference between throw and throws in Java

There are many differences between throw and throws keywords. A list of
differences between throw and throws are given below:

No. throw throws


1) Java throw keyword is used to Java throws keyword is used to declare
explicitly throw an exception. an exception.
2) Checked exception cannot be Checked exception can be propagated
propagated using throw only. with throws.
3) Throw is followed by an Throws is followed by class.
instance.
4) Throw is used within the Throws is used with the method
method. signature.
5) You cannot throw multiple You can declare multiple exceptions
exceptions. e.g.
public void method()throws
IOException,SQLException.

Java throw example

1. void m(){
2. throw new ArithmeticException("sorry");
3. }

Java throws example

1. void m()throws ArithmeticException{


2. //method code
3. }

Java throw and throws example

1. void m()throws ArithmeticException{


2. throw new ArithmeticException("sorry");
3. }

You might also like