Advertisement
wingman007

Java_ErrorHandling

Nov 23rd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package errorhandling;
  8.  
  9. /**
  10.  *
  11.  * @author fmi
  12.  */
  13. public class ErrorHandling {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         // TODO code application logic here
  20.         try {          
  21.            // int a = 10;
  22.            // int b = 0;
  23.            // int z = a/b;
  24.            
  25.            double a = 10;
  26.            double b = 0;
  27.            double z = a/b;
  28.  
  29.            System.out.println(z);      
  30.         }
  31.         // catch (Exception err) { // catch all
  32.         catch ( ArithmeticException err) { // narrowing down the type of error you expect
  33.             System.out.println(err.getMessage());
  34.         }
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement