小编典典

最终何时执行?

java

我有嵌套尝试此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块有returncontinue语句。

什么时候doSomeThingVeryImportant()执行?当我得到Exception时,我得到了NumberFormatException

我只想在执行任何catch块之后也执行finally块。


阅读 211

收藏
2020-11-23

共1个答案

小编典典

The finally block always executes when the try block exits单击)。

2020-11-23