Detecting if a program was run by Visual Studio, as opposed to run from Windows Explorer

If you’re doing this to determine if it is in any debugger (clarified by @JaredPar), you can use Debugger.IsAttached in the exception handler.

try
{
    // ...
}
catch(Exception ex)
{
    if (!Debugger.IsAttached)
    {
        ExceptionHandler.Frob(ex);
    }
    else
    {
        throw;
    }
}

Alternatively:

public static void Frob(Exception ex)
{
    if (Debugger.IsAttached)
    {
        Debugger.Break();
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)