Saturday, 28 January 2012
JAVA: Difference between throw & throws
Do you like this Article?
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).
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).
Subscribe to:
Post Comments (Atom)









4 Responses to “JAVA: Difference between throw & throws”
27 March 2012 20:57
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.
25 August 2012 23:23
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.
18 October 2012 08:20
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 also...by 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...
3 May 2013 04:28
dre3
Post a Comment