java try catch 程序流程什么时候中断? [英] java try catch when is the program flow interrupted?

查看:76
本文介绍了java try catch 程序流程什么时候中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我不太熟悉 Java 中的异常处理,因此:正如主题在基本的 try/catch 块中所说,当我在 Try 块中捕获异常时,程序流程何时中断?

Hello i am not that familiar with Exception Handling in Java so: As the Topic says in a basic try/catch block, when i catch an Exception in the Try block, when is the Program flow interrupted?

try{
    //some code that raises an Exception
}catch(Exception e){
    // react to interrupt or continue program flow
}finally{
    // always done after the catch
}
//when is this code executed?

finally 语句总是在 try catch 之后执行,那么在 catch 部分必须做什么才能中断程序或让程序继续?

The finally statement is always executed after a try catch, so what has to be done in the catch part to either interrupt the program or let the program continue?

推荐答案

any 异常发生时,指令流中断.

Instruction flow is interrupted when any exception occurs anywhere.

如果异常发生在try范围内,并且异常类可以分配给"中指定的类catch 子句,然后控制转移到 catch 块的开头.(如果异常类不是可分配的",那么异常只是冒泡"到下一个外部 try 块或线程 EH.)

If the exception occurs in a try range, and the exception class is "assignable to" the class specified in the catch clause, then control is transferred to the beginning of the catch block. (If the exception class is not "assignable" then the exception simply "bubbles up" to the next outer try block or the thread EH.)

如果 catch 块没有抛出异常(或重新抛出原始异常),则该异常被视为已处理",并在 catchtry 的子句.这可能意味着流在 finally 的末尾继续之前进入 finally 块.

If the catch block does not throw an exception (or rethrow the original one) then the exception is considered "handled", and execution continues immediately after the list of catch clauses for that try. This may mean that flow goes into the finally block before continuing at the end of the finally.

如果未捕获到异常,或者在 catch 块中(重新)发出异常信号,则在异常冒泡"之前执行任何后续的 finally 块起来".

If the exception is not caught, or an exception is (re)signalled in the catch block, then any following finally block is executed, before the exception "bubbles up".

如果 returntrycatch 块中执行,则任何 finallyfinally 之前执行代码>返回生效.

If a return is executed in the try or catch block then any finally is executed before the return takes effect.

这篇关于java try catch 程序流程什么时候中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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