Advertisement
wingman007

Java_StackTrace

Nov 23rd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 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 stacktrace;
  8.  
  9. /**
  10.  *
  11.  * @author fmi
  12.  */
  13. public class StackTrace {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         // TODO code application logic here
  20.         System.out.println("Start main");
  21.         m1();
  22.         System.out.println("End main");
  23.     }
  24.    
  25.     public static void m1() {
  26.        System.out.println("second method m1");
  27.        m2();
  28.     }
  29.    
  30.      public static void m2() {
  31.        System.out.println("last method m2");
  32.         try {
  33.             // start with this
  34.             // int x = 10;
  35.             // int y = 0;
  36.             // int z = x / y;
  37.  
  38.             // second step change the code to double
  39.             double x = 10.0;
  40.             double y = 0.0;
  41.             double z = x / y;
  42.             System.out.println( z );
  43.         }
  44.         // catch ( Exception err ) { // "catch all"
  45.         catch ( ArithmeticException err) { // narrowing down the type of error you expect
  46.                 System.out.println( err.getMessage( ) ); // / by zero,  second Infinity
  47.         }
  48.     }  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement