MSVS Inside and Outside Exception Time Exception

I call the following function: somewhere in the program that will throw an exception

public static List<Templates> LoadTemplates()
{
    // ...
    // System.Threading.Thread.CurrentThread.ManagedThreadId == 1 // ID written to log file
    System.IO.Directory.GetFiles("does_not_exist_directory");
    // ...
}

And I'm trying to catch the default exception Program.cs

try
{
    // System.Threading.Thread.CurrentThread.ManagedThreadId == 1
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}
catch (Exception ex)
{
    MessageBox.Show("ERROR CAUGHT");
}
finally { // do clean up }

When launched in MSVS, the exception is thrown as expected. But at startup, double-clicking .exe in the output directory displays an exception in the message box with a message

EDIT:

To catch an error when running .exe from the output directory, the code must be compiled with the handling of the Application.ThreadException event

Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new Form());

But then MSVS will behave undesirably by displaying its own "Unsolved Exception" dialog box in the MSWS "Troubleshooting Tips" format.

How can I make sure it behaves the same from MSVS?

+5
3

MSVS , , MSDN, woni .

(, , ). , MSVS , MSVS, . , , MSVS " ", .

, continue (F5), , MSVS , .

MSVS , .

0

, LoadTemplates . , MessageBox . Visual Studio.

, AppDomain.CurrentDomain.UnhandledException:

[STAThread]
static void Main() {
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
    MessageBox.Show("Unhandled exception");
}
0

All Articles