0
Throw vs throws
what is the different of throw and throws in java
2 Respostas
+ 2
Throws clause is used to declare an exception and throw keyword is used to throw an exception explicitly. -- Google
+ 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();
}