0

What is difference between throw and throws used in exceptions handelling???

please explain with example.

28th Nov 2016, 6:20 PM
Ravindra
Ravindra - avatar
3 Respuestas
+ 4
"throws" is used in method declaration to warn the user code may raise exceptions. "throw" is used to actually raise an exception when the program encounters an abnormal state. Look at https://code.sololearn.com/c1cpWGnqTiDz/#java for an example.
28th Nov 2016, 6:38 PM
Jean-Hugues de Raigniac
Jean-Hugues de Raigniac - avatar
+ 2
throw - java throw keyword is used to explicitly throw an exception. checked exception cannot be propagated using throw only. throw is followed by an instance. throw is used within the method. you cannot throw multiple exception. Throws - java throws keyword is used to declare an exception. checked exception can be propagated with throws throws is followed by class throws is used with the method signature you can declare multiple exceptions.
14th Dec 2016, 4:01 AM
jyoti nayal
jyoti nayal - avatar
0
throw keyword is used to throwException from any method or static block in Java while throws keyword, used in method declaration, denoted which Exception can possible be thrown by this method. They are not interchangeable.
28th Nov 2016, 7:52 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar