473,396 Members | 2,002 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 1182
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

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...
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: 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...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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.