Catching base Exception class in .NET

前端 未结 16 1936
心在旅途
心在旅途 2020-12-05 19:06

I keep hearing that

catch (Exception ex)

Is bad practise, however, I often use it in event handlers where an operation may for example go

16条回答
  •  粉色の甜心
    2020-12-05 19:14

    It is bad practice in the sense that you shouldn't do it everywhere.

    In this case, I would consider it the only reasonable solution as your exception could be truly anything. The only possible improvement would be to add extra handlers before your catch everything for specific error cases where you could do something about the exception.

提交回复
热议问题