C# best practice error handling and passing error messages

后端 未结 4 501
独厮守ぢ
独厮守ぢ 2021-01-15 02:28

I am using asp.net and I am always struggling for a neat way to handle errors and if there are any, to pass the errormessage to the user. For example, I have an User class,

4条回答
  •  星月不相逢
    2021-01-15 03:16

    It all depends on the type of issue you have with the query execution. Those issues could be anything from no records found to a connection failing. If the problem is something you can test for, which the absence of records would be, you can test for that and present your user with a message stating that no records were found. Even if a connection fails, you should be able to test for that and tell your user.

    For issues you cannot test for, depending on the type of application you are writing, you may want to let the application fail and use some framework like ELMAH log and report the error.

    try these links which come from my other post on this topic for more information

    Code Analysis Team Blog

    Martin Fowler - Fail Fast

    MSDN on Exception Handling

    Checked vs Unchecked Exceptions

    Also, this excellent article was posted recently

提交回复
热议问题