ExceptionExample.
java 29-01-2022 04:37
1 /*
2 Example of Exception and Exception
3 Handling.
4 */
5 class ExceptionExample
6 {
7 public static void main(String[] args)
8 {
9 int a = [Link](args[0]);
10 int b = [Link](args[1]);
11 int c = a/b;
12 [Link]("Value of c = "+c);
13 }
14 }
15
Page 1 of 1
Different Exception got by the above program.
[Link] 29-01-2022 04:35
1 /*
2 Example of Exception and Exception
3 Handling.
4 use of try and catch.
5 */
6 class ExceptionExampleWithSol
7 {
8 public static void main(String[] args)
9 {
10 try{
11 int a = [Link](args[0]);
12 int b = [Link](args[1]);
13 int c = a/b;
14 [Link]("Value of c = "+c);
15 }
16 catch(ArrayIndexOutOfBoundsException aiob)
17 {
18 [Link]("Pls pass 2 int values");
19 }
20 catch(NumberFormatException nfe)
21 {
22 [Link]("Pls pass integer values");
23 }
24 catch(ArithmeticException ae)
25 {
26 [Link]("Pls dont pas 2 val ZERO");
27 }
28 }
29 }
30
Page 1 of 1
Output after Exception handling done by try and catch in the above program.