I call the following function: somewhere in the program that will throw an exception
public static List<Templates> LoadTemplates()
{
System.IO.Directory.GetFiles("does_not_exist_directory");
}
And I'm trying to catch the default exception Program.cs
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show("ERROR CAUGHT");
}
finally {
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?