// Simple test of exception handling in stack procedure // Creates a stack of size 5; reads "count" from the command line, // does "count" pushes and 3 pops. If count < 3, you get empty stack error; // if count > 5, you get stack overflow error. // public class Test1 { public static void main(String args[]) { try { ArrayStack s = new ArrayStack(new Integer[5]); int count = Integer.parseInt(args[0]); for (int i=0; i < count; i++) s.push(i); for (int i=0; i < 3; i++) System.out.println(s.pop()); } catch (MyPopEmptyStack e) { System.out.println("Tried to pop an empty stack"); } catch (MyOverflowStack e) { System.out.println("Stack overflow"); } } // end main }