Site hosted by Angelfire.com: Build your free website today!
 

The finally Block

Java's finally block provides a mechanism that allows your method to clean up after itself regardless of what happens within the try block. Use the finally block to close files or release other system resources.

    try {
        open an output file ...
        do something ...
        close the opened file ...
    } catch (Type1Exception e) {
        handle exception...
    } catch (Type2Exception e) {
        handle exeception...
    } finally {
        close the output file if one was opened
    }