Unhandled Exceptions outside of VS

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Some of us on the .net framework were working on an issue that I've
encountered. It seems that in this code, the catch will not catch the
exception outside of Visual Studio. If run straight from the exe, it'll
generate an unhandled exception.

With some more testing, I've noticed this also happens with Application.Run.

Any Ideas?

Thanks!

using System;
using System.Windows.Forms;

public class Test : Form
{
public Test()
{
Load += new EventHandler(LoadEventHandler);
}

private void LoadEventHandler(object sender, EventArgs args)
{
throw new Exception("Hello");
}

static void Main()
{
try
{
new Test().ShowDialog();
}
catch (Exception e)
{
Console.WriteLine ("Caught "+e);
}
}
}
 
Hello Bryce,

Exceptions are not propagated to the creator of a Windows Form message pump. You can catch the exception using the Application.ThreadException event:
http://msdn.microsoft.com/library/d...ationClassThreadExceptionTopic.asp?frame=true

Regards.


"Bryce Covert" <[email protected]> escribió en el mensaje | Some of us on the .net framework were working on an issue that I've
| encountered. It seems that in this code, the catch will not catch the
| exception outside of Visual Studio. If run straight from the exe, it'll
| generate an unhandled exception.
|
| With some more testing, I've noticed this also happens with Application.Run.
|
| Any Ideas?
|
| Thanks!
|
| using System;
| using System.Windows.Forms;
|
| public class Test : Form
| {
| public Test()
| {
| Load += new EventHandler(LoadEventHandler);
| }
|
| private void LoadEventHandler(object sender, EventArgs args)
| {
| throw new Exception("Hello");
| }
|
| static void Main()
| {
| try
| {
| new Test().ShowDialog();
| }
| catch (Exception e)
| {
| Console.WriteLine ("Caught "+e);
| }
| }
| }
 
Back
Top