How many statements in a try/catch statement?

前端 未结 13 1251
予麋鹿
予麋鹿 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:34

    In accordance with what jldupont says, I try to always separate my potential risk statements into multiple try/catch blocks. That way when something goes wrong, you know exactly where it was and you can have specific error messages for each problem.

    0 讨论(0)
提交回复
热议问题