/* Author : Michael Robinson Program : exceptions.java Purpose : Checks the status of a file Updated : Dec 15, 2099 */ import java.util.*; public class exceptions { public static void process() { Scanner input = new Scanner( System.in ); int x = 1; //to handle the do while int fn = 0; int sn = 0; do //this is do while loop { try { System.out.print( " Enter first number : " ); fn = input.nextInt(); System.out.print( " Enter second number : " ); sn = input.nextInt(); //if divide by zero occurs, Java jumps to catch int result = fn/sn; //if divide by zero occurs this line does NOT execute x = 2; } catch(Exception e) //catches ALL errors, can print e { System.out.println(" Division by zero NOT possible"); System.out.println(" Error = " + e.getMessage() ); } finally { System.out.println( " At finally. The try catch" + " terminates here\n" ); } } while( x == 1 ); //go back to the beginning of do loop //only if NOT divide by zero error float result2 = (float)fn/sn; System.out.printf( " %d / %d = %.2f", fn, sn, result2 ); System.out.println( "\n\nEnd Exception e sample" ); }//end public static void process() public static void main( String arg[] ) { process(); }//end public static void main( String arg[] ) }//end public class exceptions