none
Friendly custom error messages RRS feed

  • 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.

    Wednesday, May 19, 2010 3:38 PM

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.

    • Proposed as answer by Mike_999 Wednesday, May 19, 2010 4:17 PM
    • Marked as answer by sirkal Wednesday, May 19, 2010 5:45 PM
    Wednesday, May 19, 2010 4:02 PM
  • 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
    Wednesday, May 19, 2010 4:23 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.

    • Proposed as answer by Mike_999 Wednesday, May 19, 2010 4:17 PM
    • Marked as answer by sirkal Wednesday, May 19, 2010 5:45 PM
    Wednesday, May 19, 2010 4:02 PM
  • 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
    Wednesday, May 19, 2010 4:23 PM