How many statements in a try/catch statement?

前端 未结 13 1423
予麋鹿
予麋鹿 2021-01-12 12:42

Should I put multiple statements in a try and then catch all possible exceptions, or should I put only one statement in the try statement?

Example:



        
13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 13:22

    It depends of the case , but it's important to notice that in the first case MaybeThrowFooBarException() is nerver called if MaybeThrowIOException() throws an exception, and in the second case MaybeThrowFooBarException will be allways called unless a exception is rethrown in the first catch

提交回复
热议问题