如果两个渔获物和finally块抛出异常,会发生什么?抛出、异常、两个、发生

2023-09-02 11:56:07 作者:哭泣的迷彩

如果两个渔获物和finally块抛出的异常会发生什么事?

What happens if both catch and finally blocks throw exception?

推荐答案

最后块抛出一个异常,这将有效地隐藏除了从抓块将是一个最终抛出。它要么抓时记录异常,或确保finally块本身不抛出异常,因此重要的,否则你可以得到抛出异常被扼杀了,从来没有见过。

When the finally block throws an exception, it will effectively hide the exception thrown from the catch block and will be the one ultimately thrown. It is therefore important to either log exceptions when caught, or make sure that the finally block does not itself throw an exception, otherwise you can get exceptions being thrown that are stifled and never seen.