Can Try Statements Be Nested


  • 7 Aug, 2012

    try statements can be nested.

    for example,

    import java.io.*;
    public class NestedTry{
      public static void main (String args[])throws IOException  {
      int num=2,res=0;
      
      try{
      FileInputStream fis=null;
      fis = new FileInputStream (new File (args[0]));
      try{
      res=num/0;
      System.out.println("The result is"+res);
      }
      catch(ArithmeticException e){
      System.out.println("divided by Zero");
      }
      }
      catch (FileNotFoundException e){
      System.out.println("File not found!");
      }
      catch(ArrayIndexOutOfBoundsException e){
      System.out.println("Array index is Out of bound! Argument required");
      }
      catch(Exception e){
      System.out.println("Error.."+e);
      }
    }
    }

    Comments Received:
    Please give your suggestions and feedback:
  • 29 Dec, 2011

    Try statements may be tested.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.