473,327 Members | 1,919 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,327 software developers and data experts.

Application unhandled exception

In Main I register ThreadException to handle unhandled exceptions
Application.ThreadException += new
ThreadExceptionEventHandler(App_ThreadException);
The method will show a MessageBox or a Form instead of .NET 2 default
dialog. However I don't get the code work. What am I missing?

One silly question. Can I post .NET 2 questions here or should I post to
msdn2?

Thanks in advance,
Shehab.
Aug 14 '06 #1
3 1566
Shehab Kamal <Sh*********@discussions.microsoft.comwrote:
In Main I register ThreadException to handle unhandled exceptions
Application.ThreadException += new
ThreadExceptionEventHandler(App_ThreadException);
The method will show a MessageBox or a Form instead of .NET 2 default
dialog. However I don't get the code work. What am I missing?
I don't know. You need to run outside the debugger for one thing,
because under the debugger VS hacks your application message loop and
inserts its own code into the call stack - highly frustrating, I
personally find. Also, it will only catch exceptions that are invoked on
the GUI thread via message loop dispatching - things like painting,
click events, etc.

This console application works well for me:

---8<---
using System;
using System.Windows.Forms;

static class App
{
static void Main()
{
Application.ThreadException += delegate
{
Console.WriteLine("Caught!");
};

Form form = new Form();
form.Click += delegate
{
throw new Exception();
};

Application.Run(form);
}
}
--->8---
One silly question. Can I post .NET 2 questions here or should I post to
msdn2?
..NET 2 is .NET as well.

-- Barry

--
http://barrkel.blogspot.com/
Aug 14 '06 #2
Hello Shehab,

Add event handler for all threads in the appdomain

appdomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);
SKIn Main I register ThreadException to handle unhandled exceptions
SKApplication.ThreadException += new
SKThreadExceptionEventHandler(App_ThreadException) ;
SKThe method will show a MessageBox or a Form instead of .NET 2
SKdefault
SKdialog. However I don't get the code work. What am I missing?
SKOne silly question. Can I post .NET 2 questions here or should I
SKpost to msdn2?
SK>
SKThanks in advance,
SKShehab.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 14 '06 #3
The 2 answers complete each other.
I have thrown an excpetion after clicking a button and it was handled by App
not AppDomain.
I have thrown an exception from the constructor and it was handled by the
AppDomain not App. However the "sorry for inconvenience" message box appears,
can I get rid of it or it is built in windows?

Thanks for the 2 answers.
Aug 15 '06 #4

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

Similar topics

12
by: Rakesh | last post by:
Hi, I am catching unhandled exception by attached an event handler on the Application.ThreadException event. This will ensure that I could handle all uncaught exceptions on the main thread. ...
2
by: Alex | last post by:
My Problem is that although i have added a handler to Application.ThreadException and it works fine for my application exceptions, it does not fire if an exception is generated inside an event...
5
by: Sam Loveridge | last post by:
Hi All. I'm hoping someone can point me in the direction of a solution to unhandled exceptions in MDI child forms causing the application to crash. I've found various articles describing a...
8
by: mike2036 | last post by:
I have an application (that has unmanaged code) and when I launch it without 'FullTrust' permissions (LocalIntranet_Zone), it crashes. When I set 'FullTrust' permissions, it launches fine. Is...
1
by: Bob | last post by:
In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple app and found that it was easier to implement unhandled exception management tah it was in Vs2003 (vb.net) You can, if you...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.