816 Exception Handling Chapter 14 77 // process (Web design programs)
816 Exception Handling Chapter 14 77 // process attempts to divide by zero 78 catch ( ArithmeticException arithmeticException ) { 79 JOptionPane.showMessageDialog( this, 80 arithmeticException.toString(), 81 “Arithmetic Exception”, 82 JOptionPane.ERROR_MESSAGE ); 83 } 84 } 85 86 // method quotient demonstrated throwing an exception 87 // when a divide-by-zero error occurs 88 public double quotient( int numerator, int denominator ) 89 throws DivideByZeroException 90 { 91 if ( denominator == 0 ) 92 throw new DivideByZeroException(); 93 94 return ( double ) numerator / denominator; 95 } 96 97 // execute application 98 public static void main( String args[] ) 99 { 100 DivideByZeroTest application = new DivideByZeroTest(); 101 102 application.setDefaultCloseOperation( 103 JFrame.EXIT_ON_CLOSE ); 104 } 105 106 } // end class DivideByZeroTest Fig. 14.2A simple exception-handling example with divide by zero (part 3 of 3). Fig. 14.2
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.