我有嵌套尝试此Java代码:
try { try { [ ... ] { catch (Exception ex) { showLogMessage(ex); return; } while (condition == true) { try { [ ... ] { catch (Exception ex) { showLogMessage(ex); continue; } [ ... ] } } catch (NumberFormatException e) { showLogMessage(e); } finally { doSomeThingVeryImportant(); }
我想知道是否finally在发生异常时始终执行。我问这个是因为catch块有return或continue语句。
finally
return
continue
什么时候doSomeThingVeryImportant()执行?当我得到Exception时,我得到了NumberFormatException?
doSomeThingVeryImportant()
Exception
NumberFormatException
我只想在执行任何catch块之后也执行finally块。
The finally block always executes when the try block exits(单击)。
The finally block always executes when the try block exits