0

What is the difference between throw and throws ??

17th Jul 2016, 7:18 AM
AnsHuman Aaditya
AnsHuman Aaditya - avatar
3 Respostas
+ 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 :(
17th Jul 2016, 8:15 AM
William Jing
William Jing - avatar
+ 1
It's quite helpful dude 👍
18th Jul 2016, 6:43 PM
AnsHuman Aaditya
AnsHuman Aaditya - avatar
0
throws is handle the compile time and throw is handle the runtime exceprions
10th Aug 2016, 3:31 PM
srilekha