473,387 Members | 1,512 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,387 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 2653
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.