473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ApplicationException unhandled by user code

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(fals e);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadExceptio n);
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.

Apr 24 '07 #1
4 15883
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


"bg***@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(fals e);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadExceptio n);
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.

Apr 24 '07 #2
Try this:

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

"bg***@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(fals e);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadExceptio n);
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.

Apr 24 '07 #3
On 24 Apr, 13:04, Siva M <shiva...@online.excite.comwrote:
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(fals e);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadExceptio n);
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?

Apr 24 '07 #4
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


"bg***@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(fals e);
Application.ThreadException += new
ThreadExceptionEventHandler(new
ThreadExceptionHandler().ApplicationThreadExceptio n);
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.
Jul 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
6
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use...
2
by: Charles | last post by:
I need to find a way to share information between two classes, one is an employee class and the other is a custom error class that inherits from ApplicationException. These two classes are part of...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
4
by: Tad Marshall | last post by:
Hi, I'm having limited luck getting an ApplicationException to work right in my code. This is VB.NET, VS 2003, Windows XP SP2, .NET Framework 1.1. I thought it would be convenient to take...
5
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded...
2
by: Bob | last post by:
I MUST be able to trap unhandled exceptions, bring the thread to a routine that then closes the thread on which the execption occurred without closing or affecting the other threads. Think of an...
1
by: bg_ie | last post by:
Hi, I have the following Program.cs - namespace TestFrameworkApplication { static class Program { /// <summary> /// The main entry point for the application.
0
by: Autostrad | last post by:
I use V C++ 2008. From the code below I am trying to make a program that will ask the user to enter a number into the text box. If the user click “OK”, without entering a number a dialog box will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.