0

Throw vs throws

what is the different of throw and throws in java

11th Sep 2017, 11:15 PM
i MIMO
i MIMO - avatar
2 Respostas
+ 2
Throws clause is used to declare an exception and throw keyword is used to throw an exception explicitly. -- Google
11th Sep 2017, 11:27 PM
Samantha Jordan
Samantha Jordan - avatar
+ 2
The throws indicate if a function/method could possibly throw an exception. We usually use try{ // } catch(Exception e){ // } To handle these Exceptions. The throw is used to tell the program to execute an exception right there and then. If you're not handling your exception with TRY and CATCH you'll need to indicate it with THROWS. Example: private void devideNull() throws NullException{ int i = 5 / 0; } private void Error() throws Exception{ throw new Exception(); }
12th Sep 2017, 12:21 AM
Limitless
Limitless - avatar