Java try-catch-finally Exception Handling
Details
- Details
- Category: Java
- Created on Wednesday, 07 November 2012 14:48
- Last Updated on Wednesday, 07 November 2012 14:48
- Published on Wednesday, 07 November 2012 14:48
- Written by Administrator
- Hits: 9272
try-catch-finally simple code in java :
package com.developerpages.snippets.basics;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class trycatsfinalyexample {
public static void main(String[] args) throws FileNotFoundException {
FileReader in = null;
try {
in = new FileReader("test.txt");
// processing file ...
} catch (IOException ex) {
System.out.println("Error opening file...");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
System.out.println("Cannot close file ...");
}
}
}
}
}