General Exception Handling Strategy for .NET

后端 未结 11 1478
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 08:51

I’m used to having try/catch blocks in every method. The reason for this is so that I can catch every exception at the point of infraction and log it. I understand, from my

11条回答
  •  北海茫月
    2020-12-15 09:42

    You can see everything at stack trace - no need to try/catch every method.

    Stick to few rules:

    1. Use try/catch only if you want to use a custom exception type
    2. Define a new exception type only if upper levels needs to know that
    3. Try/catch at top level instead of doing that for each method

提交回复
热议问题