throws Exception in finally blocks

后端 未结 15 2332
慢半拍i
慢半拍i 2020-11-29 18:04

Is there an elegant way to handle exceptions that are thrown in finally block?

For example:

try {
  // Use the resource.
}
catch( Excep         


        
15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 18:30

    I typically use one of the closeQuietly methods in org.apache.commons.io.IOUtils:

    public static void closeQuietly(OutputStream output) {
        try {
            if (output != null) {
                output.close();
            }
        } catch (IOException ioe) {
            // ignore
        }
    }
    

提交回复
热议问题