C# best practice error handling and passing error messages

后端 未结 4 539
独厮守ぢ
独厮守ぢ 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:01

    Either by wrapping in a using statement or having a Try/Finally to ensure the db connection is disposed, as that particular type of exception could be trouble for you.

    This free book by Karl Seguin has a chapter on Exception Handling which should make things quite clear for you.

    Bubble up the exception to the UI where it can be handled according to your style there. For unhandled exceptions, as mentioned below, ELMAH is very useful.

提交回复
热议问题