public class TestExceptions
1: //TestExceptions.java
2: //Just to see what exception is thrown ...
3:
4: import java.util.Scanner;
5:
6: public class TestExceptions
7: {
8: public static void main(String[] args)
9: {
10: try
11: {
12: System.out.println(5/0); //ArithmeticException thrown
13: }
14: catch (ArithmeticException e)
15: {
16: System.out.println("Sorry!");
17: }
18: //System.out.println(Math.sqrt(-1)); //Actually we get NaN
19: //System.out.println(args[5]); //ArrayIndexOutOfBoundsException thrown
20: }
21: }
22:
23: /*
24: * Note that the exceptins above are runtime exceptions, and as such are
25: * unchecked and do not need to be explicitly dealt with by the programmer.
26: */
27: