可能重复:
finally 块是否总是运行?
让我们想象以下场景:
public void myMethod() throws MyException
try
{
// do something
// an Exception (for example an individual written MyException which extends
// "Exception" is thrown here
}
catch (OtherException e)
{
// do something
}
finally
{
// do something else
}
}
如果在 try 块中抛出“MyException”并且不会被捕获 - 它们最终会到达块,对吗?
如果它是一个运行时异常,会被抛出怎么办?会到达 finally 块吗?
是否存在无法到达 finally 块的情况?
感谢您的回答:-)