is illusory detect an difference occurred before i entered finally block?


in java, there an glorious proceed detect an difference occurred before controlling finally block? traffic "close()" statements, it's common need difference doing within finally block. ideally, we'd wish say both exceptions beget adult (as both competence enclose useful information). wholly proceed i cruise have non-static outmost try-catch-finally range save anxiety thrown exception. following beget "saved" difference adult any start finally block.



is there some-more glorious proceed doing this? maybe an api exhibit this?



here's severe formula i'm articulate about:



throwable t = null; 
try {
stream.write(buffer);
} catch(ioexception e) {
t = e; //need save difference finally
pitch e;
} finally {
try {
stream.close(); //may pitch exception
} catch(ioexception e) {
//is there something improved saving difference exception block?
if(t!=null) {
//propagate review difference "cause"--not great, nonetheless i mean.
pitch new ioexception("could tie finally block: " + e.getmessage(),t);
} else {
pitch e; //just pass up
}
}//end close
}


obviously, there array identical kludges competence secure saving difference an member variable, returning method, etc... nonetheless i'm looking something bit some-more elegant.



maybe something thread.getpendingexception() something similar? matter, there an glorious fortitude languages?



this doubt indeed spawned comments carried an engaging question.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members