Try Catch blocks inside or outside of functions and error handing

前端 未结 6 627
野性不改
野性不改 2020-12-30 21:35

This is more a general purpose programming question than language specific. I\'ve seen several appraoches to try and catches.

One is you do whatever preprocessing on

6条回答
  •  再見小時候
    2020-12-30 22:04

    I generally consider if as the caller of the method I can use an exception in any way (like, to recover from it by taking a different approach) or if it makes no difference and just went wrong if the exception occurs. So in the former case I'll declare the method to throw the exception while in the latter I'll catch it inside of the method and don't bother the caller with it.

提交回复
热议问题