Tutorials

Java Exception Handling


throw vs throws


 

We have already covered both the throw and throws keyword in details in their respective sections.

 

To read in detail about throw, click here

To read in detail about throws, click here

 

In this chapter, we will focus only on major differences between throw and throws keyword in java. 

 

throw

throws

Throw keyword is used to explicitly throw the exception.

Throws keyword is used to declare the exceptions that the method might throw.

Throw keyword is used inside the method

Throws keyword is used at the method level

Throw keyword can only throw instance of the exception class

Throws keyword can declare exception class itself.

Throw keyword can only throw one exception at a time

Throws keyword can declare multiple exceptions at a time.

 



Please Share this page
Views : 62