How can I determine which exceptions can be thrown by a given method?

前端 未结 9 908
感情败类
感情败类 2020-11-30 22:41

My question is really the same as this one \"Finding out what exceptions a method might throw in C#\". However, I would really like to know if anyone knows of a way to deter

相关标签:
9条回答
  • 2020-11-30 23:12

    Unlike java C# does not have the concept of checked exceptions.

    On a macro level you should catch everything and log or inform the user of the error. When you know about the specific exceptions a method may raise then definetly handle that appropriately but be sure to let any other exceptions bubble up (preferably) or log them, otherwise you will have bugs that you will not be able to find and generally make life miserable for anyone hired to help reduce the bug list - have been there, not fun! :)

    0 讨论(0)
  • 2020-11-30 23:21

    John Robbins had a series of articles on creating FxCop rules including an MSDN article that would indicate which exceptions were thrown. This was to warn about missing XML documentation for the exceptions but the idea would be the same.

    0 讨论(0)
  • 2020-11-30 23:22

    My methodology for this type of situation is to handle all the exceptions that I want to and then override the UnhandledException event of the application to log any other's that I don't know about. Then if I come up against any that I think I could possibly resolve then I would just update accordingly.

    Hope that helps!

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