Untitled

 avatar
unknown
java
2 years ago
8.4 kB
4
Indexable
//////////1 
* @author vinod
 */
public class JavaExceptionExample {
    public static void main (String args[]){
    try{
       int data=100/0;
    }catch(ArithmeticException e){
        System.out.println(e);
    }
        System.out.println("rest of the code");
    }
}
/////////////2 

 * @author vinod
 */
public class Main1 {
     public static void main (String args[]){
     int data=50/5;
         System.out.println("rest of the code");
     }
}


////////////2-after-fix
/**
 *
 * @author vinod
 */
public class JavaExceptionExample {
    public static void main (String args[]){
    try{
       int data=100/0;
    }catch(ArithmeticException e){
        System.out.println(e);
    }
        System.out.println("rest of the code");
    }
}

/////////////////3

/**
 *
 * @author vinod
 */
public class Main1 {
     public static void main (String args[]){
    
         try{
         int data=50/0;
         }catch(ArithmeticException e)
         {
         
          System.out.println(e);
          }
         System.out.println("rest of the code2");
     }
}


//////////////////////4

/**
 *
 * @author vinod
 */
public class Main1 {
     public static void main (String args[]){
    
         try{
         int data=50/0;
         }catch(Exception e)
         {
         
          System.out.println(e);
          }
         System.out.println("rest of the code2");
     }
}
///////////////////////////////5

public class Main1 {
     public static void main (String args[]){
    
         try{
         int data=50/0;
         }catch(Exception e)
         {
         
          System.out.println("erorr");
          }
         System.out.println("rest of the code2");
     }
}
////////////////////////////

/**
 *
 * @author vinod
 */
public class Main1 {
     public static void main (String args[]){
        int i=50;
        int j=0;
        int data;
        
         try{
         data=i/j;
         }catch(Exception e)
         {
         
          System.out.println(i/(j+i));
          }
        
     }
}
//////////////////////

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class Multicatchblock {
   public static void main (String[]args){
   try{
   int a[]=new int[5];
   a[5]=30/0;
   }catch(ArithmeticException e){
       System.out.println("Arithmetic Exception occurs");
   }catch(ArrayIndexOutOfBoundsException e ){
       System.out.println("array ArrayIndexOutOfBoundsException occurs");
   }
   catch (Exception e){
       System.out.println("parent exception occurs");
   }
   
       System.out.println("rest of the code");
   } 
}
/////////////////////////////////////////

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class Multicatchblock {

    public static void main(String[] args) {
        try {
            //int a[]=new int[5];
            //a[5]=30/0;

            int b[] = new int[5];
            System.out.println(b[10]);

        } catch (ArithmeticException e) {
            System.out.println("Arithmetic Exception occurs");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("array ArrayIndexOutOfBoundsException occurs");
        } catch (Exception e) {
            System.out.println("parent exception occurs");
        }

        System.out.println("rest of the code");
    }
}
///////////////////////////////////
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class Multicatchblock {

    public static void main(String[] args) {
        try {
            //int a[]=new int[5];
            //a[5]=30/0;

            int b[] = new int[5];
            System.out.println(b[10]);
            
           //  int c[] = new int[5];
            // c[5]=30/0;
           // System.out.println(c[10]);
            

        } catch (ArithmeticException e) {
            System.out.println("Arithmetic Exception occurs");
        }/* catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("array ArrayIndexOutOfBoundsException occurs");
        } catch (Exception e) {
            System.out.println("parent exception occurs");
        }
*/
        System.out.println("rest of the code");
    }
}
///////////////////////
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class simplethrownexception {
    public static void divideNumbers()throws ArithmeticException{
        int numertor=10;
        int denominator=0;       
     
              //not comlete  
                if(denominator==0){
                throw new ArithmeticException ("canot divide by zero");
                 }
                double results = (double) numertor/ denominator;
                
                    System.out.println("rest of division"+results);
               
    }
    
    public static void main (String []args){
        
        try{
        divideNumbers();
        }catch(ArithmeticException e){
            System.out.println("Exception caught"+e.getMessage());
        
        }
    }}
//////////////////

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class testfinal {
    public static void main(String[]args){
       try{
       
           System.out.println("inside the try block");
           
           int data=25/0;
           System.out.println("data");
       
       }
        
        catch (NullPointerException e){
            System.out.println(e);
        }
       finally{
       
           System.out.println("final block is always executed");
       } 
        System.out.println("rest of the code...");
    }
    
}
///////////////////////////////
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

/**
 *
 * @author vinod
 */
public class testfinal {
    public static void main(String[]args){
       try{
       
           System.out.println("inside the try block");
           
           int data=25/0;
           System.out.println(data);
       
       }
        
        catch (ArithmeticException e){
            System.out.println(e);
        }
       finally{
       
           System.out.println("final block is always executed");
       } 
        System.out.println("rest of the code...");
    }
    
}
////////////////////////////////

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package newpackage;

import java.io.IOException;

/**
 *
 * @author vinod
 */
public class TestThrows {

    void m() throws IOException {
        throw new IOException("device error");
    }

    void n() throws IOException {
        m();
    }

    void p() {
        try {
            n();
        } catch (Exception e) {
            System.out.println("exception handeld");
        }

    }

    public static void main(String[] args) {
        TestThrows obj = new TestThrows();
        obj.p();
        System.out.println("normal flow....");

    }

}








Editor is loading...
Leave a Comment