Answered by:
Friendly custom error messages

Question
-
Hi,
I am trying to display friendly error messages to users and system exception messages to developers. Is there a C# way to do this. What I mean is, when a developer is debugging the issue should be able to see the actual error message, where as the complied app should only display friendly custom error message without revealing any system (e.g.: database) information. Hope my question is clear.
Thank you in advance.
Answers
-
The easiest way to do this is to put a check inside of your "catch" block that would basically check whether the current user is a normal user or a developer. From there you can either cutsomize the exception or display it as is. A simple if, else statement should do the trick.
Alternatively, if the developers only work in the debug mode, you could check the value of the "DEBUG" constant.
-
You need to read up on c debug compiler directive. Below is an example
#if DEBUG
Do this in debug;
#else
do this optionaly if not in debug
#endif
My .NET Blog: http://michaelcrump.net- Proposed as answer by Michael Crump, MVP, MCPD Wednesday, May 19, 2010 4:23 PM
- Marked as answer by sirkal Wednesday, May 19, 2010 5:45 PM
All replies
-
The easiest way to do this is to put a check inside of your "catch" block that would basically check whether the current user is a normal user or a developer. From there you can either cutsomize the exception or display it as is. A simple if, else statement should do the trick.
Alternatively, if the developers only work in the debug mode, you could check the value of the "DEBUG" constant.
-
You need to read up on c debug compiler directive. Below is an example
#if DEBUG
Do this in debug;
#else
do this optionaly if not in debug
#endif
My .NET Blog: http://michaelcrump.net- Proposed as answer by Michael Crump, MVP, MCPD Wednesday, May 19, 2010 4:23 PM
- Marked as answer by sirkal Wednesday, May 19, 2010 5:45 PM