What happens if both catch and finally blocks throw exception?

前端 未结 5 610
谎友^
谎友^ 2020-12-13 18:26

What happens if both catch and finally blocks throw exception?

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 18:56

    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.

提交回复
热议问题