Checking For Debug Mode In Code

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Hi, is there a way to tell in code if you are in Debug|Release mode?

I have an error handling routine that sends me a e-mail if an error is
caught. This is great when the users are working with the release version
of the app but not when developing in the IDE. I would rather turn the
e-mail into a MessageBox. What I would like to do is something like this:

private void MyErrorHandler()

if( <in debug mode> )
MessageBox.Show("error info");
else
SendErrorEmail("error info");

Any help is greatly appreciated.
 
Just to complete the example:

#if DEBUG
MessageBox.Show("error info");
#else
SendErrorEmail("error info");
#endif

Eric
Tamir Khason said:
You can use [Conditional("DEBUG")] or #if DEBUG directions

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


Greg Smith said:
Hi, is there a way to tell in code if you are in Debug|Release mode?

I have an error handling routine that sends me a e-mail if an error is
caught. This is great when the users are working with the release version
of the app but not when developing in the IDE. I would rather turn the
e-mail into a MessageBox. What I would like to do is something like this:

private void MyErrorHandler()

if( <in debug mode> )
MessageBox.Show("error info");
else
SendErrorEmail("error info");

Any help is greatly appreciated.
 
Check System.Diagnostics.Debugger.IsAttached

--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
Back
Top