Back to Top

Saturday, 28 January 2012

JAVA: Difference between throw & throws

throw is used to throw an exception in a program, explicitly.
Whereas,  throws is included in the method's declaration part, with a list of exceptions that the method can possible throw. It is necessary for all exceptions(except for Error & RuntimeException & their sub-classes).

4 Responses to “ JAVA: Difference between throw & throws ”

Arraylist tutorial example java said...
28 March 2012 at 09:27

throw can also be used in flow control like breaking from switch statement. see 3 difference between throw and throws in java for more details.

Biswajit Pradhan said...
26 August 2012 at 11:53

Using throws we only provide information related to unhandled exceptions of a method.throws keyword would not perform any kind of actions.
BUT using 'throw' we explicitly raise an exception and throw would not provide any information rather it perform certain action.

Gokul Manoharan said...
18 October 2012 at 20:50

We have lot of differences in between throw and throws...when we are using throws which we can use within that method signature but throw we can use inside the method else SIB using throws keyword along with that we can pass multiple exceptions but using throw keyword we can't pass multiple exception...and here we can produce our own exception like we can call explicit exceptions...but in throws we use only checked Exception.... By Gokul Lara Technologies Bangalore...

aaaaa said...
3 May 2013 at 16:58


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs