C# try {} catch {}

后端 未结 11 2415
既然无缘
既然无缘 2021-02-08 10:51

hi and thanks for reading. im a newbie in programming and C# and sockets programming. in my code i try and catch problems to provide fault tolarence in my app. the following:

11条回答
  •  被撕碎了的回忆
    2021-02-08 11:19

    Yes it would work, but it would not do the same, since all exceptions and not only the specific ones would be catched.

    This is usually not what you want, as the general rule is to catch only exceptions which you know how to handle. There are some situations where you need such a catch-all to redirect the exception (like accross thread boundaries or in async calls) or do some cleanup work if something - anything - goes wrong (but then you usually re-throw the exception after doing your work).

提交回复
热议问题