July 22nd, 2013, 03:26 AM
Throw v/s Throws
How are you all...
I am new to the java and learns core java right now...
Any one please tell me the difference between the Throw and Throws..
What is the basic difference between them and how it is used...
thank you in advance ..
July 22nd, 2013, 11:00 AM
The keyword throw is used to actually cause an exception to occur. It must be used with an instance of a Throwable.
e.g. throw new NullPointerException()
The keyword throws precedes a list of exceptions that a method might throw. It is required for checked exceptions which have not been handed in the method, but you can also list unchecked exceptions.
The unchecked exceptions are RuntimeException, Error, and their subclasses.