java:exceptions_intro

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
java:exceptions_intro [2015/03/03 06:19]
gthanos [Finaly Block]
java:exceptions_intro [2015/03/03 06:36]
gthanos [Exception Handler]
Line 116: Line 116:
   ​   ​
   public String readFile(String path) {   public String readFile(String path) {
-  ​+
     try {     try {
       File file = new File (path);       File file = new File (path);
Line 123: Line 123:
       String inputLine;       String inputLine;
       StringBuffer strDocument = new StringBuffer();​       StringBuffer strDocument = new StringBuffer();​
-      ​try { +      while ((inputLine = in.readLine()) != null) { 
-        ​while ((inputLine = in.readLine()) != null) { +        strDocument.append(inputLine);​
-          strDocument.append(inputLine); +
-        } +
-        fReader.close();​ +
-      }catch(IOException ex) { +
-        System.out.println("​IOException occured while opening file or reading from file "​+path);​ +
-        System.out.println("​Exiting..."​);​ +
-        System.exit(1);+
       }       }
 +      fReader.close();​
       return strDocument.toString();​       return strDocument.toString();​
     }     }
Line 138: Line 132:
       System.out.println("​The specified file was not found at "+ path);       System.out.println("​The specified file was not found at "+ path);
       return "";​       return "";​
 +    }   
 +    catch(IOException ex) {
 +      System.out.println("​IOException occured while opening file or reading from file "​+path);​
 +      System.out.println("​Exiting..."​);​
 +      System.exit(1);​
     }    ​     }    ​
 +    return "";​
   }   }
   ​   ​
Line 151: Line 151:
   }   }
  
-} +}</​code>​
-</​code>​+
  
 ==== Finaly Block ==== ==== Finaly Block ====
java/exceptions_intro.txt · Last modified: 2019/04/20 05:02 by gthanos