Unhandled Exceptions outside of VS

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);
}
}
}
 
G

Guest

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);
| }
| }
| }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top