0
What is difference between throw and throws used in exceptions handelling???
please explain with example.
3 Réponses
+ 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.
+ 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.
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.