//---------------------------------------- // Demonstration of exceptions //---------------------------------------- public class Exceptions { public static void main (String[] args) { int x = 10; int y = 2; int[] z = {10, 20, 30, 40 ,50}; String w = "Hello World"; Divide t = null; int maxint = 2147483647; System.out.println (x/y); // possible division by zero System.out.println (z[4]); // possible array index out of bounds System.out.println (w.charAt(10)); // possible srting index out of bounds t = new Divide(5,2); // possible exception propagation (division by zero) System.out.println (t.getValue()); // possible null pointer reference System.out.println(maxint+1); // needs defining a new exception System.out.println ("This text will not be printed if an exception occurs"); } }