最终何时执行? [英] When finally is executed?

查看:65
本文介绍了最终何时执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带嵌套try的这段Java代码:

I have this java code with nested try:

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 语句.

I want to know if finally is always executed when I get an exception. I ask this because catch blocks have return or continue statements.

何时执行 doSomeThingVeryImportant()?当我得到 Exception 时,我得到 NumberFormatException ?

When is doSomeThingVeryImportant() executed? When I get an Exception on when I get a NumberFormatException?

我只希望在执行任何catch块之后也要执行finally块.

I only want if after any catch block is executed, the finally block is executed also.

推荐答案

try块总是在try块退出时执行( 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆