Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
See more: , +
Hello,

it's been a while since i last posted a message on this site. Usually i can find what i'm looking for, but not today.

What i'm trying to find is an easy way to centralize exception messages in a .Net application. So the whole exception handling is taken care of, but currently the programmers are making up the messages that the exception throws. I made a separation between user-friendly messages and the actual exception that is being logged, but even then you can get many different messages for the same kind of problem.

What i was thinking about was work with enums that translate into a message in our custom exception, but thinking this over i fear its going be hell to manage as it grows and grows.

Does anyone have any thoughts on this? Pointing me to a good article would be very much appreciated as well.


Regards,

Franz
Posted
Comments
RaisKazi 10-Sep-14 14:18pm    
Good Question. If this is related to Asp.net then I used Application_Error event of Global.asax. But not sure if that's a Best Practice in terms of Exception handling.

1 solution

Possibly this Code Project article fits your needs: "Exception Handling Best Practices in .NET"[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Sep-14 0:36am    
Something tells me not to trust this article. Some points are really good, but some... Just read it:

"Don't catch (Exception) more than once per thread". There are fields when capturing exception two or more times per thread is the best technique. You catch "raw" exception in different places, and then, those different places throw a different "application" exception with different semantic. This is too important feature of structured exception handling to ignore.

"Don't ever swallow exceptions" This chapter is almost true. The big problem is this "almost". Without giving the idea when exceptions to this rule has to be made, this positive advice becomes a disaster. The exclusions are quite rare, but they are so important and, in fact, typical, so not mentioning them is a real educational crime.

"Exceptions should be marked [Serializable]" The motivation to this advice, "you never know" is a bad adviser. Some exceptions are internal by design...

—SA
CPallini 11-Sep-14 1:20am    
I think it is overall good. Experts like you know when a different path is better.
Sergey Alexandrovich Kryukov 11-Sep-14 1:54am    
Well, I already mentioned that many other points are good, do I have to agree with you. 5ed your answer; hope my little notes can help...
—SA
Franz.net 15-Sep-14 11:18am    
I read this article and it makes some good points! Though it doesn't cover my predicament

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900