import java.util.*; public class TestIntStack { public static void main(String[] args) { int x; IntStack stack = new IntStack(); // push the values 10, 20, 30, 40, 50 for ( x = 10; x < 60; x=x+10 ) { System.out.println("Pushing " + x + "."); stack.push(x); } // display the stack contents System.out.println("\nDumpstack:"); stack.dumpStack(); // report the top value and pop it // ordinarily we would capture the popped value while (! stack.isEmpty()) { System.out.println("Popping " + stack.peek() + "."); stack.pop(); } // try to pop the empty stack System.out.println("\nIntentionally popping an empty stack."); try { x = stack.pop(); } catch (EmptyStackException e) { System.out.println("\nCaught EmptyStackException!"); System.out.println("We could do some useful work here."); } } }