RSS feed [root] /design /weblog /exception




login:

password:

title search:




 


Tue Feb 27 04:31:48 GMT 2007

handle exception in finally



This blog discuss the code at finally can affect code at catch block - http://mult.ifario.us/articles/2006/07/26/java-brain-teaser


ExternalResource resource = resourceManager.open();
Throwable e1 = null;
try {
// Use the resource (stream, db connection, ...)
} catch (Throwable e) {
e1 = e;
} finally {
try {
resource.close();
if (e1 != null) throw e1;
} catch (Throwable e2) {
// Pretend e2 doesn't already have a cause...
if (e1 != null) e2.initCause(e1);
throw e2;
}
}

http://bagotricks.com[..]06/02/06/dropping-the-ball-er-exception/

or this, can be better looking


try {
InputStream is = new FileOutputStream("hello.txt");
try {
is.write("hello");
finally {
is.close();
}
} catch (IOException e) {
e.printStrackTrace();
}

http://jroller.com/page/davinci?entry=finally_in_catch


(google search) (amazon search)
second
download zip of files only