In C#, how do I know which exceptions to catch?

前端 未结 11 1372
抹茶落季
抹茶落季 2020-12-30 08:33

I\'ve gotten in the habit of using a general catch statement and I handle those exceptions in a general manner. Is this bad practice? If so, how do I know which specific exc

11条回答
  •  一个人的身影
    2020-12-30 09:18

    The methods you run will generally show what exceptions can be thrown. You can then catch accordingly.

    If it's your own code, you can generally see what will be thrown, or use the underlying classes exceptions as a guide on what you will need to catch.

    I recommend a few links:

    • Exception Handling in C#
    • Try..Catch
    • Exceptions and Exception Handling

提交回复
热议问题