/****** * * Class demo of try/catch stuff * Feb 6 * ****/ class TryCatch { public static void main(String[] args){ print(" -- Try/Catch --"); int x, y, z; x = 10; y = 0; z = 0; print(" Here's what the numbers are to start:"); printThreeNumbers(x,y,z); try { // Here's the part that may crash. z = x/y; } catch (Exception e){ // Here's what to do if it crashes. print("Something bad happened: '" + e.getMessage() + "'"); } print(" And here's what they are now:"); printThreeNumbers(x,y,z); } // Talk to the nice user. public static void printThreeNumbers(int x, int y, int z){ print(" x = '" + x + "'"); print(" y = '" + y + "'"); print(" z = '" + z + "'"); } // Jim doesn't like to type this over and over. public static void print(String s){ System.out.println(s); } }