Home » Core Java » Difference between throw and throws in Java

Difference between throw and throws in Java

Difference between throw and throws in Java -is an entry level java interview question asked in interview rounds.Though both throw and throws are keywords which sounds same ,but there are many difference between these.Let us see some code example ,before we jump to comparison table.

throws Example ::

throw new Example ::


throw new and throws Example ::

OutPut

Comparison Table of throws and throw ::

throws throw 
throws is a  keyword which  used to declare an exception. throw is a keyword which is used to explicitly throw a particular exception.
Using throws ,you can throw multiple exception. only one exception can be thrown.
throws has Exception class name. throw has new operator to define only one instance of any particular exception.
Checked exception can be propagated with throws. Checked exception can not be propagated with throw new.
throws is a part of of method signature throw is a part of method body

Leave a comment

Your email address will not be published. Required fields are marked *

16 + 6 =