Exception Handling in .net web apps

后端 未结 6 832
盖世英雄少女心
盖世英雄少女心 2021-01-31 12:36

I admit it: I don\'t bother with too much exception handling. I know I should do more but I can never wrap my head around where to start and where to stop. I\'m not being lazy.

6条回答
  •  你的背包
    2021-01-31 13:04

    Start off with a global exception handler such as http://code.google.com/p/elmah/.

    Then the question comes down to what kind of application are you writting and what kind of user experience do you need to provide. The more rich the user experience the better exception handling you'll want to provide.

    As an example consider a photo hosting site which has disk quotas, filesize limits, image dimension limits, etc. For each error you could simply return "An error has occured. Please try again". Or you could get into detailed error handling:

    • "Your file is to large. Maximum filesizes is 5mb."
    • "Your image is is to large. Maximum dimensions are 1200x1200."
    • "Your album is full. Maximum storage capacity is 1gb".
    • "There was an error with your upload. Our hampsters are unhappy. Please come back later."

    etc. etc.

    There is no one size fits all for exception handling.

提交回复
热议问题