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

Threading & Exceptions


The following first throws the nasty exception dialog, and only then show me
the message.
Is there a way to avoid this?
This occur both inside & outside VS.
public class Test
{
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(((Exception)e .ExceptionObject).Message)
;

}

private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(e.Exception.M essage);

}

[ STAThread()]

public static void Main(string [] args)

{

System.AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

System.Windows.Forms.Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);

Test();

}

private static void Test()

{

throw new InvalidOperationException("Test");

}

}

}
Nov 16 '05 #1
4 2654
wrap it in a try-catch block

"Ayende Rahien" <Ay****@no.spam> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...

The following first throws the nasty exception dialog, and only then show me the message.
Is there a way to avoid this?
This occur both inside & outside VS.
public class Test
{
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(((Exception)e .ExceptionObject).Message) ;

}

private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(e.Exception.M essage);

}

[ STAThread()]

public static void Main(string [] args)

{

System.AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

System.Windows.Forms.Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);

Test();

}

private static void Test()

{

throw new InvalidOperationException("Test");

}

}

}

Nov 16 '05 #2
This is an example, the point is that I'm trying to have a general unhandled
exception filter, so my code won't just burp and die without me doing
something about it.
The problem is that while this works (a bit), I still get that damned dialog
about unhandled exception.

"Dave" <no****************@wi.rr.com> wrote in message
news:ep*************@tk2msftngp13.phx.gbl...
wrap it in a try-catch block

"Ayende Rahien" <Ay****@no.spam> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...

The following first throws the nasty exception dialog, and only then show
me
the message.
Is there a way to avoid this?
This occur both inside & outside VS.
public class Test
{
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(((Exception)e .ExceptionObject).Message) ;

}

private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(e.Exception.M essage);

}

[ STAThread()]

public static void Main(string [] args)

{

System.AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

System.Windows.Forms.Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
Test();

}

private static void Test()

{

throw new InvalidOperationException("Test");

}

}

}


Nov 16 '05 #3
You cannot handle an exception as an unhandled exception - its very name
(unhandled) means that you did not handle it. The only way you can handle it
is in a catch block.

All the unhandled exception handler does is provide the code with a
notification that it happened so it can do some cleanup (log it to disk,
cleanup etc) before the CLR either terminates the app (if the unhandled
exception occurred on the main thread or on a thread that wandered in from
unmanaged code) or swallows it (if it occurred on a thread you created
manually, a threadpool thread, etc).

The terminology you used (exception filter) implies you are thinking of this
as if it were a Win32 exception filter, and this is not what the handler is.
"Ayende Rahien" <Ay****@no.spam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This is an example, the point is that I'm trying to have a general unhandled exception filter, so my code won't just burp and die without me doing
something about it.
The problem is that while this works (a bit), I still get that damned dialog about unhandled exception.

"Dave" <no****************@wi.rr.com> wrote in message
news:ep*************@tk2msftngp13.phx.gbl...
wrap it in a try-catch block

"Ayende Rahien" <Ay****@no.spam> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...

The following first throws the nasty exception dialog, and only then show
me
the message.
Is there a way to avoid this?
This occur both inside & outside VS.
public class Test
{
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(((Exception)e .ExceptionObject).Message)
;

}

private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)

{

System.Windows.Forms.MessageBox.Show(e.Exception.M essage);

}

[ STAThread()]

public static void Main(string [] args)

{

System.AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

System.Windows.Forms.Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
Test();

}

private static void Test()

{

throw new InvalidOperationException("Test");

}

}

}



Nov 16 '05 #4
Ayende Rahien wrote:
The following first throws the nasty exception dialog, and only then
show me the message.
Is there a way to avoid this?
This occur both inside & outside VS.


By the way, here is a the minimal code to reproduce the problem:

<code>
using System;
namespace UnhandledExcp
{
public class Test
{
private static void CurrentDomain_UnhandledException(
object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
}

public static void Main()
{
System.AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler
(CurrentDomain_UnhandledException);

throw new InvalidOperationException("Test");
}
}
}
</code>

The question is now:
How to avoid the Excpetion-Dialog if it runs outside of VS?

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 16 '05 #5

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

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
4
by: Ayende Rahien | last post by:
The following first throws the nasty exception dialog, and only then show me the message. Is there a way to avoid this? This occur both inside & outside VS. public class Test { private...
0
by: ʹÃûÑï | last post by:
ORA-03114: not connected to ORACLE && MS's Bug?? DataBase:Oracle 817 using OracleClient,net framework 1.1 I'm using ADO.Net in C# with Oracle 817. and following is my public data access...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
7
by: Phill W. | last post by:
Can anyone recommend a good reference on Threading (Framework 1.1)? I'm particularly confused about how to call a method in my "main" thread from another one. - or more, one day ;-) I've...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
10
by: Janto Dreijer | last post by:
I have been having problems with the Python 2.4 and 2.5 interpreters on both Linux and Windows crashing on me. Unfortunately it's rather complex code and difficult to pin down the source. So...
1
by: Mathieu Prevot | last post by:
2008/8/13 Parimala <parimala.b@accord-soft.com>: Hi, a terminate method is given here: http://sebulba.wikispaces.com/recipe+thread2 so you can terminate the thread by: (...)
0
by: Edwin.Madari | last post by:
1. check out the Caveats for thread module: http://docs.python.org/lib/module-thread.html Threads interact strangely with interrupts: the KeyboardInterrupt exceptionwill be received by an...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.