I am using:
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
But, my function is not run when an exception is thrown on another
computer running WinXP SP2, and I have no idea why. Instead, the
Windows error report screen appears. Isn't the above supposed to work
no matter what? What am I doing wrong?
Zytan 17 2160
Zytan <zy**********@gmail.comwrote:
I am using:
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
But, my function is not run when an exception is thrown on another
computer running WinXP SP2, and I have no idea why. Instead, the
Windows error report screen appears. Isn't the above supposed to work
no matter what? What am I doing wrong?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hello Zytan,
What kind of applocation? winform based?
Try to use AppDomain.CurrentDomain.UnhandledException handling
---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
ZI am using:
Z>
ZApplication.ThreadException += new
ZSystem.Threading.ThreadExceptionEventHandler(Appl ication_ThreadExcept
Zion);
ZBut, my function is not run when an exception is thrown on another
Zcomputer running WinXP SP2, and I have no idea why. Instead, the
ZWindows error report screen appears. Isn't the above supposed to
Zwork no matter what? What am I doing wrong?
Z>
ZZytan
Z>
Here is a short article that summarizes a lot of this, including Registry
setting that controls the JIT Debugger Windows Error screen popup: http://www.eggheadcafe.com/articles/20051205.asp
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Zytan" wrote:
I am using:
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
But, my function is not run when an exception is thrown on another
computer running WinXP SP2, and I have no idea why. Instead, the
Windows error report screen appears. Isn't the above supposed to work
no matter what? What am I doing wrong?
Zytan
Could you post a short but complete program which demonstrates the
problem?
No, I cannot, since I don't have access to the machines on which my
code does not work. I think the single line of code that I provided
is all that is required to make this work, and for some reason that
line of code does not do anything on certain WinXP machines. I am
dumbfounded that the results vary.
Zytan
What kind of applocation? winform based?
Yes, a Windows Form.
Try to use AppDomain.CurrentDomain.UnhandledException handling
Michael, I tried this, and rejected this for two reasons:
1. When in the debugger, this catch will run its own code before the
debugger has a chance to catch the exception itself. It gets in the
debugger's way.
2. When in release, Windows catches the error first. This is the most
important job for it to do, and it doesn't do it.
Zytan
Here is a short article that summarizes a lot of this, including Registry
setting that controls the JIT Debugger Windows Error screen popup:
http://www.eggheadcafe.com/articles/20051205.asp
Unfortunately, this articles just enumerates all ways to catch
exceptions. It doesn't summarize anything else, like about how they
work, which one is better, in which situations one is better, which
one could be used in deployment, etc. All it is are methods to help
the developer catch the problem on her own machine.
So, I'm still at square one, trying to determine why the following
code 'fires' on some WinXP machines (mine), but not on others (that I
unfortunately can't get my hands on, at the moment). It's hard to
beta test something that is not consistent.
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
Zytan
Well, as the other posters (and the article) indicated, there are only two
handlers to catch an unhandled exception event:
Thread.GetDomain().UnhandledException += new
UnhandledExceptionEventHandler(Application_Unhandl edException);
Application.ThreadException += new ThreadExceptionEventHandler(
Application_ThreadException );
if you have them both wired up correctly in your application, and there is
an unhandled exception, then depending on whether it occured on the main
thread or elsewhere, one of these is going to sqwawk.
Bear in mind these are EVENT handlers, not "exception" handlers. Once you
have an unhandled exception, your deal is gone - these are just there to give
you a last chance to perform cleanup, log the event, etc.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Zytan" wrote:
Here is a short article that summarizes a lot of this, including Registry
setting that controls the JIT Debugger Windows Error screen popup: http://www.eggheadcafe.com/articles/20051205.asp
Unfortunately, this articles just enumerates all ways to catch
exceptions. It doesn't summarize anything else, like about how they
work, which one is better, in which situations one is better, which
one could be used in deployment, etc. All it is are methods to help
the developer catch the problem on her own machine.
So, I'm still at square one, trying to determine why the following
code 'fires' on some WinXP machines (mine), but not on others (that I
unfortunately can't get my hands on, at the moment). It's hard to
beta test something that is not consistent.
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
Zytan
Well, as the other posters (and the article) indicated, there are only two
handlers to catch an unhandled exception event:
Thread.GetDomain().UnhandledException += new
UnhandledExceptionEventHandler(Application_Unhandl edException);
Application.ThreadException += new ThreadExceptionEventHandler(
Application_ThreadException );
Yes, and I've fully tested them both. On my development machine,
WinXP, Application.ThreadException works correctly in debug and
release, and the other one doesn't wory correctly in either. By
'correctly', I mean I want the debugger to grab the exception first,
and in release mode, I want my code to grab the exception before
Windows does.
But, for some reason, this behaviour is not consistent. I have no
idea why.
if you have them both wired up correctly in your application, and there is
an unhandled exception, then depending on whether it occured on the main
thread or elsewhere, one of these is going to sqwawk.
Indeed, I could hook them both up, and I have tried that, and it
pretty much guarantees, perhaps on all computers, that the code will
be run. Unfortunately, this also means you can't debug the exception
on the spot, that's why I avoided it. Maybe I'll just have to bite
the bullet, and lose my debugger's ability to grab exceptions, and let
my code always catch it, if that's what I need to do to ensure other
computers in a release build will catch them, as well.
Bear in mind these are EVENT handlers, not "exception" handlers. Once you
have an unhandled exception, your deal is gone - these are just there to give
you a last chance to perform cleanup, log the event, etc.
Yes, of course, I just use this to log the error, and email the crash
report.
Zytan
Maybe I'll just have to bite
the bullet, and lose my debugger's ability to grab exceptions, and let
my code always catch it, if that's what I need to do to ensure other
computers in a release build will catch them, as well.
Hm, I'll just NOT run the one that doesn't work if I'm in debug mode.
That way the release mode can catch everything and anything it wants,
and it should. And in debug mode, hey, I don't even need any of these
things running, actually, if the debugger is there, since it always
catches everything (right?).
Zytan
Thread.GetDomain().UnhandledException += new
UnhandledExceptionEventHandler(Application_Unhandl edException);
It is difficult to test this, since on my machine, JIT catches this.
What would happen on another non-development machine, without JIT?
Also, how can you get the exception information from
UnhandledExceptionEventArgs? It has a ExceptionObject, but it's
'object', not 'Exception'. Can it be typecast into Exception? Well,
it can, but would that work?
I can't test this out since I can't even get my code to run without
the JIT jumping in first!
Zytan
On May 9, 12:52 pm, Zytan <zytanlith...@gmail.comwrote:
Well, as the other posters (and the article) indicated, there are only two
handlers to catch an unhandled exception event:
Thread.GetDomain().UnhandledException += new
UnhandledExceptionEventHandler(Application_Unhandl edException);
Application.ThreadException += new ThreadExceptionEventHandler(
Application_ThreadException );
Yes, and I've fully tested them both. On my development machine,
WinXP, Application.ThreadException works correctly in debug and
release, and the other one doesn't wory correctly in either. By
'correctly', I mean I want the debugger to grab the exception first,
and in release mode, I want my code to grab the exception before
Windows does.
But, for some reason, this behaviour is not consistent. I have no
idea why.
if you have them both wired up correctly in your application, and there is
an unhandled exception, then depending on whether it occured on the main
thread or elsewhere, one of these is going to sqwawk.
Indeed, I could hook them both up, and I have tried that, and it
pretty much guarantees, perhaps on all computers, that the code will
be run. Unfortunately, this also means you can't debug the exception
on the spot, that's why I avoided it. Maybe I'll just have to bite
the bullet, and lose my debugger's ability to grab exceptions, and let
my code always catch it, if that's what I need to do to ensure other
computers in a release build will catch them, as well.
Well, there are ways to avoid the problem with you're running under
the debugger.
For example, I do this:
if (!System.Diagnostics.Debugger.IsAttached)
{
Application.ThreadException += ...
AppDomain.CurrentDomain.UnhandedException += ...
}
That way I don't hook up the exception handlers when I'm running under
the debugger.
Interesting article, Peter. The only problem is that my attempts to
print it have all met with mixed success (multiple blank pages
followed by just a part of the article). Probably something to do with
the way the site formats its articles.
On May 9, 4:23 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Here is a short article that summarizes a lot of this, including Registry
setting that controls the JIT Debugger Windows Error screen popup:
http://www.eggheadcafe.com/articles/20051205.asp
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Zytan" wrote:
I am using:
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
But, my function is not run when an exception is thrown on another
computer running WinXP SP2, and I have no idea why. Instead, the
Windows error report screen appears. Isn't the above supposed to work
no matter what? What am I doing wrong?
Zytan
Peter,
What *I* really want to do is set up a machine so that my applications
NEVER pop a dialog when they crash.
For some odd reason on one of our production machines, if one of
my .NET exes dies, it pops the "Debug or cancel" dialog.
Unfortunately, this machine runs batch jobs, and the dialog hangs the
batch stream for the night. The guy in charge of it is not amused.
Is there a way to force that stupid dialog off? I'm already trapping
and logging the errors. I have no need of the dialog.
On May 9, 4:23 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Here is a short article that summarizes a lot of this, including Registry
setting that controls the JIT Debugger Windows Error screen popup:
http://www.eggheadcafe.com/articles/20051205.asp
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Zytan" wrote:
I am using:
Application.ThreadException += new
System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);
But, my function is not run when an exception is thrown on another
computer running WinXP SP2, and I have no idea why. Instead, the
Windows error report screen appears. Isn't the above supposed to work
no matter what? What am I doing wrong?
Zytan
Well, there are ways to avoid the problem with you're running under
the debugger.
For example, I do this:
if (!System.Diagnostics.Debugger.IsAttached)
{
Application.ThreadException += ...
AppDomain.CurrentDomain.UnhandedException += ...
}
I just use #if !DEBUG ... #endif. But, I suppose it is the debugger
that I'm concerned with, so I should just check that, as you do, and
be certain.
Thanks!
Zytan
On May 10, 8:01 am, Zytan <zytanlith...@gmail.comwrote:
Well, there are ways to avoid the problem with you're running under
the debugger.
For example, I do this:
if (!System.Diagnostics.Debugger.IsAttached)
{
Application.ThreadException += ...
AppDomain.CurrentDomain.UnhandedException += ...
}
I just use #if !DEBUG ... #endif. But, I suppose it is the debugger
that I'm concerned with, so I should just check that, as you do, and
be certain.
Yes. #if !DEBUG tests to see if the program was _compiled_ for debug
or release.
System.Diagnostics.Debugger.IsAttached checks to see if the program is
actually running under the debugger. It depends upon what behaviour
you want. I occasionally put debug versions on our test servers for
users to play with, and in that environment I want errors trapped and
logged, even though the program was compiled for debug.
Yes. #if !DEBUG tests to see if the program was _compiled_ for debug
or release.
System.Diagnostics.Debugger.IsAttached checks to see if the program is
actually running under the debugger. It depends upon what behaviour
you want. I occasionally put debug versions on our test servers for
users to play with, and in that environment I want errors trapped and
logged, even though the program was compiled for debug.
Right, thanks for your help, Bruce!
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: valued customer |
last post by:
Is there a more concise way to do something like the the
desired code below?
The gripe is with the try-catch syntax. It takes *way* too
many lines of code to evaluate a conditional expression...
|
by: Ralph Krausse |
last post by:
I created a try/catch/finally but when an expection is thrown, the
catch does not handle it... (I know this code is wrong, I want to
force the error for this example)
try
{
DataSet ds = new...
|
by: Solution Seeker |
last post by:
Hi,
I have a Problem when i try to put a Try Catch Block Outside all the
Functions in a Class. But in .Net, it throws an error.
I like to catch all the Unhandled Exception that occured inside...
|
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...
|
by: Nick |
last post by:
Hi there,
This probably wont make much sense but I'm getting an unhandled
exception being thrown in the following line...
Try
While True
Redraw control as necessary
End While
Catch ex as...
|
by: CodeSlayer |
last post by:
Hi all,
This one really has me and the other .Net developers at my work
stumped. I have an application that is doing the following:
1 - attempt to validate that user can create a windows task...
|
by: Fernando Chilvarguer |
last post by:
I have a very simple test page that the only thing it does is render a
control.
This control generates and throws an error.
I need to catch the error on my ASPX page but I can't figure out...
|
by: pack |
last post by:
Is "catch" in C# going to catch all exception, or it just catch the
exceptions induced by "throw"? Will it also catch those "structured
exceptions" that could be either from system modules or other...
|
by: rhaazy |
last post by:
I am looking for some feedback on using try catch statements.
Usually when I start a project I use them for everything, but stop
using them as often after the "meat n' potatos" of the project is...
|
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
|
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...
|
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...
|
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...
|
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...
|
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: 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...
|
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: 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,...
| |