Putting try catch finally block inside another finally block

前端 未结 5 1116
孤独总比滥情好
孤独总比滥情好 2021-02-07 00:57
 try {
 } catch() {}
 finally {
     try {
     } catch() { }
     finally { }
 }

Is it good to have the code like above?

5条回答
  •  天涯浪人
    2021-02-07 01:42

    It's ugly, but there are cases where you can't avoid it, especially in resource clean up where you have dependent resources and the clean up of one resource can throw an exception.

    A typical example is tidying up ResultSet, Statement and Connection objects in JDBC code. Closing the ResultSet can throw an exception, but we'd still like to continue and close the Statement and Connection

提交回复
热议问题