PC Review


Reply
Thread Tools Rate Thread

ApplicationException unhandled by user code

 
 
bg_ie@yahoo.com
Guest
Posts: n/a
 
      24th Apr 2007
Hi,

I have the following Program.cs -

namespace TestFrameworkApplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadException);
Application.Run(new FormMain());
}

/// <summary>
/// Handles any thread exceptions
/// </summary>
public class ThreadExceptionHandler
{
public void ApplicationThreadException(object sender,
ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "An exception
occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
}
}

In my Form, I attempt the following -

private void button1_Click(object sender, EventArgs e)
{
ThrowException();
}

private void ThrowException()
{
throw new ApplicationException("Monkey exception");
}

But when I click on the corresponding button, I keep getting the
message "ApplicationException unhandled by user code" from the
debugger. But once I continue the debugger, the message box pops up
with the error. What is the debugger warning me about and can I switch
off this message if I am not actually doing anything incorrect?

Thanks for your help,

Barry.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      24th Apr 2007
It seems to me that you are throwing an ApplicationException, which
apparently is not the same exception type that you have code to handle for
(ThreadException).
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"(E-Mail Removed)" wrote:

> Hi,
>
> I have the following Program.cs -
>
> namespace TestFrameworkApplication
> {
> static class Program
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main()
> {
> Application.EnableVisualStyles();
> Application.SetCompatibleTextRenderingDefault(false);
> Application.ThreadException += new
> ThreadExceptionEventHandler(new
> ThreadExceptionHandler().ApplicationThreadException);
> Application.Run(new FormMain());
> }
>
> /// <summary>
> /// Handles any thread exceptions
> /// </summary>
> public class ThreadExceptionHandler
> {
> public void ApplicationThreadException(object sender,
> ThreadExceptionEventArgs e)
> {
> MessageBox.Show(e.Exception.Message, "An exception
> occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
> Application.Exit();
> }
> }
> }
> }
>
> In my Form, I attempt the following -
>
> private void button1_Click(object sender, EventArgs e)
> {
> ThrowException();
> }
>
> private void ThrowException()
> {
> throw new ApplicationException("Monkey exception");
> }
>
> But when I click on the corresponding button, I keep getting the
> message "ApplicationException unhandled by user code" from the
> debugger. But once I continue the debugger, the message box pops up
> with the error. What is the debugger warning me about and can I switch
> off this message if I am not actually doing anything incorrect?
>
> Thanks for your help,
>
> Barry.
>
>

 
Reply With Quote
 
=?Utf-8?B?U2l2YSBN?=
Guest
Posts: n/a
 
      24th Apr 2007
Try this:

Go to VS 2005 menu Tools | Options and then Debugging/General. Uncheck
'Enable Just my Code'.

"(E-Mail Removed)" wrote:

> Hi,
>
> I have the following Program.cs -
>
> namespace TestFrameworkApplication
> {
> static class Program
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main()
> {
> Application.EnableVisualStyles();
> Application.SetCompatibleTextRenderingDefault(false);
> Application.ThreadException += new
> ThreadExceptionEventHandler(new
> ThreadExceptionHandler().ApplicationThreadException);
> Application.Run(new FormMain());
> }
>
> /// <summary>
> /// Handles any thread exceptions
> /// </summary>
> public class ThreadExceptionHandler
> {
> public void ApplicationThreadException(object sender,
> ThreadExceptionEventArgs e)
> {
> MessageBox.Show(e.Exception.Message, "An exception
> occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
> Application.Exit();
> }
> }
> }
> }
>
> In my Form, I attempt the following -
>
> private void button1_Click(object sender, EventArgs e)
> {
> ThrowException();
> }
>
> private void ThrowException()
> {
> throw new ApplicationException("Monkey exception");
> }
>
> But when I click on the corresponding button, I keep getting the
> message "ApplicationException unhandled by user code" from the
> debugger. But once I continue the debugger, the message box pops up
> with the error. What is the debugger warning me about and can I switch
> off this message if I am not actually doing anything incorrect?
>
> Thanks for your help,
>
> Barry.
>
>

 
Reply With Quote
 
bg_ie@yahoo.com
Guest
Posts: n/a
 
      24th Apr 2007
On 24 Apr, 13:04, Siva M <shiva...@online.excite.com> wrote:
> Try this:
>
> Go to VS 2005 menu Tools | Options and then Debugging/General. Uncheck
> 'Enable Just my Code'.
>
>
>
> "b...@yahoo.com" wrote:
> > Hi,

>
> > I have the following Program.cs -

>
> > namespace TestFrameworkApplication
> > {
> > static class Program
> > {
> > /// <summary>
> > /// The main entry point for the application.
> > /// </summary>
> > [STAThread]
> > static void Main()
> > {
> > Application.EnableVisualStyles();
> > Application.SetCompatibleTextRenderingDefault(false);
> > Application.ThreadException += new
> > ThreadExceptionEventHandler(new
> > ThreadExceptionHandler().ApplicationThreadException);
> > Application.Run(new FormMain());
> > }

>
> > /// <summary>
> > /// Handles any thread exceptions
> > /// </summary>
> > public class ThreadExceptionHandler
> > {
> > public void ApplicationThreadException(object sender,
> > ThreadExceptionEventArgs e)
> > {
> > MessageBox.Show(e.Exception.Message, "An exception
> > occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
> > Application.Exit();
> > }
> > }
> > }
> > }

>
> > In my Form, I attempt the following -

>
> > private void button1_Click(object sender, EventArgs e)
> > {
> > ThrowException();
> > }

>
> > private void ThrowException()
> > {
> > throw new ApplicationException("Monkey exception");
> > }

>
> > But when I click on the corresponding button, I keep getting the
> > message "ApplicationException unhandled by user code" from the
> > debugger. But once I continue the debugger, the message box pops up
> > with the error. What is the debugger warning me about and can I switch
> > off this message if I am not actually doing anything incorrect?

>
> > Thanks for your help,

>
> > Barry.- Dölj citerad text -

>
> - Visa citerad text -


That worked, thanks. But why did it work?

 
Reply With Quote
 
=?Utf-8?B?UGVwYQ==?=
Guest
Posts: n/a
 
      5th Jul 2007
ThreadException event should occur on any unhandled exception in current
thread; example in MSDN throws ArgumentException as well.

Still I don't understand working with unhandled exceptions. In my
application I used Application.ThreadException event to display dialog box
when unhandled exception occured and it worked... until non-catched exception
was thrown from Application.Idle event handler. ThreadException event handler
was not called and standard .NET dialog box appeared advising to send report
to MS.

If I handle AppDomain.CurrentDomain.UnhandledException, this handler *is*
called when exception in Idle occurs. But it only informs about exception.
When my handler ends, standard .NET crash dialog box appears again.

The exception in Idle handler can also be caught by sorrounding
Application.Run with try-catch. But that would require some "goto" or "while"
to resume the application if I wish to continue after exception.

I cannot make head of it

Pepa

"Peter Bromberg [C# MVP]" wrote:

> It seems to me that you are throwing an ApplicationException, which
> apparently is not the same exception type that you have code to handle for
> (ThreadException).
> Peter
>
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
>
>
> "(E-Mail Removed)" wrote:
>
> > Hi,
> >
> > I have the following Program.cs -
> >
> > namespace TestFrameworkApplication
> > {
> > static class Program
> > {
> > /// <summary>
> > /// The main entry point for the application.
> > /// </summary>
> > [STAThread]
> > static void Main()
> > {
> > Application.EnableVisualStyles();
> > Application.SetCompatibleTextRenderingDefault(false);
> > Application.ThreadException += new
> > ThreadExceptionEventHandler(new
> > ThreadExceptionHandler().ApplicationThreadException);
> > Application.Run(new FormMain());
> > }
> >
> > /// <summary>
> > /// Handles any thread exceptions
> > /// </summary>
> > public class ThreadExceptionHandler
> > {
> > public void ApplicationThreadException(object sender,
> > ThreadExceptionEventArgs e)
> > {
> > MessageBox.Show(e.Exception.Message, "An exception
> > occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
> > Application.Exit();
> > }
> > }
> > }
> > }
> >
> > In my Form, I attempt the following -
> >
> > private void button1_Click(object sender, EventArgs e)
> > {
> > ThrowException();
> > }
> >
> > private void ThrowException()
> > {
> > throw new ApplicationException("Monkey exception");
> > }
> >
> > But when I click on the corresponding button, I keep getting the
> > message "ApplicationException unhandled by user code" from the
> > debugger. But once I continue the debugger, the message box pops up
> > with the error. What is the debugger warning me about and can I switch
> > off this message if I am not actually doing anything incorrect?
> >
> > Thanks for your help,
> >
> > Barry.
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net error with invalidcastexception was unhandled by user code LoNe4eVa Webmaster / Programming 0 16th Jul 2009 08:28 PM
System.InvalidCastException was unhandled by user code Deven Microsoft ASP .NET 2 2nd Jul 2009 02:47 AM
WCF runtime error: FaultException was unhandled by user code =?Utf-8?B?aGVyYmVydA==?= Microsoft Dot NET 0 26th Sep 2007 08:43 PM
Re: ApplicationException unhandled by user code bg_ie@yahoo.com Microsoft C# .NET 0 24th Apr 2007 02:19 PM
ApplicationException unhandled by user code bg_ie@yahoo.com Microsoft C# .NET 1 24th Apr 2007 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:40 PM.