0
What is the difference between throw and throws ??
3 odpowiedzi
+ 1
here is an example
public class Program {
static int div(int a, int b) throws ArithmeticException {
if(b == 0) {
throw new ArithmeticException("Division by Zero");
} else {
return a / b;
}
}
public static void main(String[] args) {
System.out.println(div(42, 0));
}
}
throws only exists after the method it tells others there maybe some exceptions you need to try… catch
throw is a statement that here is a exception for sure!
I am sorry I can't say it clearly :(
+ 1
It's quite helpful dude 👍
0
throws is handle the compile time and throw is handle the runtime exceprions