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.
But, suppose I create a new thread within my app and an
unhandled exception is generated in that thread, will
that exception be caught here?
Thanks in advance,
Rakesh 12 2659
No, the unhandled exceptions on other threads wont be caught.
--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht
news:04****************************@phx.gbl... 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.
But, suppose I create a new thread within my app and an unhandled exception is generated in that thread, will that exception be caught here?
Thanks in advance, Rakesh
Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of
try-catch in this case? Any other way?
Rakesh -----Original Message----- No, the unhandled exceptions on other threads wont be
caught. -- Greetz, Jan __________________________________ Read my weblog: http://weblogs.asp.net/jan "Rakesh" <an*******@discussions.microsoft.com> schreef
in berichtnews:04****************************@phx.gbl... 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.
But, suppose I create a new thread within my app and an unhandled exception is generated in that thread, will that exception be caught here?
Thanks in advance, Rakesh
.
catch (Exception e)
{
}
In the main would catch everything right?
"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of try-catch in this case? Any other way?
Rakesh -----Original Message----- No, the unhandled exceptions on other threads wont be caught. -- Greetz, Jan __________________________________ Read my weblog: http://weblogs.asp.net/jan "Rakesh" <an*******@discussions.microsoft.com> schreef
in berichtnews:04****************************@phx.gbl... 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.
But, suppose I create a new thread within my app and an unhandled exception is generated in that thread, will that exception be caught here?
Thanks in advance, Rakesh
.
You can attach a handler to the AppDomain.CurrentDomain.UnhandledException
event, but be aware that one of its limitations is that it will only work
for the default appdomain.
If you create the thread yourself then you should put a try-catch block
within the thread's start function to ensure that you will catch and handle
all exceptions. For the main thread and threads that originate in unmanaged
code, an unhandled exception will terminate the app. For threads you create
manually, threadpool threads, and finalizer threads, even though your
unhandled exception handler is called, the runtime will catch and swallow
all exceptions; the IsTerminating field in the UnhandledExceptionEventArgs
is set to false.
"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of try-catch in this case? Any other way?
Rakesh -----Original Message----- No, the unhandled exceptions on other threads wont be caught. -- Greetz, Jan __________________________________ Read my weblog: http://weblogs.asp.net/jan "Rakesh" <an*******@discussions.microsoft.com> schreef
in berichtnews:04****************************@phx.gbl... 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.
But, suppose I create a new thread within my app and an unhandled exception is generated in that thread, will that exception be caught here?
Thanks in advance, Rakesh
.
Hi Dave,
I want to know if i got you right:
So if i have only one appdomain and i attach an event
handler in the
AppDomain.CurrentDomain.UnhandledException, will that
ensure that I can handle all the uncaught exceptions
regardless of whichever thread they are in?
Rakesh -----Original Message----- You can attach a handler to the
AppDomain.CurrentDomain.UnhandledExceptionevent, but be aware that one of its limitations is that
it will only workfor the default appdomain.
If you create the thread yourself then you should put a
try-catch blockwithin the thread's start function to ensure that you
will catch and handleall exceptions. For the main thread and threads that
originate in unmanagedcode, an unhandled exception will terminate the app. For
threads you createmanually, threadpool threads, and finalizer threads,
even though yourunhandled exception handler is called, the runtime will
catch and swallowall exceptions; the IsTerminating field in the
UnhandledExceptionEventArgsis set to false.
"Rakesh" <an*******@discussions.microsoft.com> wrote in
messagenews:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way
of try-catch in this case? Any other way?
Rakesh >-----Original Message----- >No, the unhandled exceptions on other threads wont be caught. > >-- >Greetz, >Jan >__________________________________ >Read my weblog: http://weblogs.asp.net/jan >"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht >news:04****************************@phx.gbl... >> 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. >> >> But, suppose I create a new thread within my app
and an >> unhandled exception is generated in that thread,
will >> that exception be caught here? >> >> Thanks in advance, >> Rakesh >> > > >. >
.
It will catch exceptions only in the main thread. -----Original Message----- catch (Exception e) { }
In the main would catch everything right?
"Rakesh" <an*******@discussions.microsoft.com> wrote in
messagenews:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way
of try-catch in this case? Any other way?
Rakesh >-----Original Message----- >No, the unhandled exceptions on other threads wont be caught. > >-- >Greetz, >Jan >__________________________________ >Read my weblog: http://weblogs.asp.net/jan >"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht >news:04****************************@phx.gbl... >> 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. >> >> But, suppose I create a new thread within my app
and an >> unhandled exception is generated in that thread,
will >> that exception be caught here? >> >> Thanks in advance, >> Rakesh >> > > >. >
.
The only way to catch all exceptions in every thread is to enclose every
thread proc in a try/catch clause.
--
cody
[Freeware, Games and Humor] www.deutronium.de.vu || www.deutronium.tk
Watson :D
How does watson catch UE's? Cant we do something similar?
"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl... It will catch exceptions only in the main thread.
-----Original Message----- catch (Exception e) { }
In the main would catch everything right?
"Rakesh" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of try-catch in this case? Any other way?
Rakesh >-----Original Message----- >No, the unhandled exceptions on other threads wont be caught. > >-- >Greetz, >Jan >__________________________________ >Read my weblog: http://weblogs.asp.net/jan >"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht >news:04****************************@phx.gbl... >> 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. >> >> But, suppose I create a new thread within my app and an >> unhandled exception is generated in that thread, will >> that exception be caught here? >> >> Thanks in advance, >> Rakesh >> > > >. >
.
Could have a launcher program that does a process start and catches the
exception there?
<di********@discussion.microsoft.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl... Watson :D
How does watson catch UE's? Cant we do something similar?
"Rakesh" <an*******@discussions.microsoft.com> wrote in message news:05****************************@phx.gbl... It will catch exceptions only in the main thread.
-----Original Message----- catch (Exception e) { }
In the main would catch everything right?
"Rakesh" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl... > Hi Jan, > > Thanks! > > So do u mean that we have to go about the same old way of> try-catch in this case? Any other way? > > Rakesh > > > > >-----Original Message----- > >No, the unhandled exceptions on other threads wont be > caught. > > > >-- > >Greetz, > >Jan > >__________________________________ > >Read my weblog: http://weblogs.asp.net/jan > >"Rakesh" <an*******@discussions.microsoft.com> schreef > in bericht > >news:04****************************@phx.gbl... > >> 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. > >> > >> But, suppose I create a new thread within my app and an> >> unhandled exception is generated in that thread, will> >> that exception be caught here? > >> > >> Thanks in advance, > >> Rakesh > >> > > > > > >. > >
.
I think that is what Dave meant. But be awere it's only in the current app
domain!
--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht
news:02****************************@phx.gbl... Hi Dave,
I want to know if i got you right:
So if i have only one appdomain and i attach an event handler in the AppDomain.CurrentDomain.UnhandledException, will that ensure that I can handle all the uncaught exceptions regardless of whichever thread they are in?
Rakesh -----Original Message----- You can attach a handler to the AppDomain.CurrentDomain.UnhandledExceptionevent, but be aware that one of its limitations is that it will only workfor the default appdomain.
If you create the thread yourself then you should put a try-catch blockwithin the thread's start function to ensure that you will catch and handleall exceptions. For the main thread and threads that originate in unmanagedcode, an unhandled exception will terminate the app. For threads you createmanually, threadpool threads, and finalizer threads, even though yourunhandled exception handler is called, the runtime will catch and swallowall exceptions; the IsTerminating field in the UnhandledExceptionEventArgsis set to false.
"Rakesh" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of try-catch in this case? Any other way?
Rakesh >-----Original Message----- >No, the unhandled exceptions on other threads wont be caught. > >-- >Greetz, >Jan >__________________________________ >Read my weblog: http://weblogs.asp.net/jan >"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht >news:04****************************@phx.gbl... >> 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. >> >> But, suppose I create a new thread within my app and an >> unhandled exception is generated in that thread, will >> that exception be caught here? >> >> Thanks in advance, >> Rakesh >> > > >. >
.
try this
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(Domain_Exception_Ha ndler);
it should handle all the exceptions that occur in the app domain no matter
on which thread.
<di********@discussion.microsoft.com> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl... Could have a launcher program that does a process start and catches the exception there?
<di********@discussion.microsoft.com> wrote in message news:Oo**************@TK2MSFTNGP12.phx.gbl... Watson :D
How does watson catch UE's? Cant we do something similar?
"Rakesh" <an*******@discussions.microsoft.com> wrote in message news:05****************************@phx.gbl... It will catch exceptions only in the main thread.
>-----Original Message----- >catch (Exception e) >{ >} > >In the main would catch everything right? > > >"Rakesh" <an*******@discussions.microsoft.com> wrote in message >news:05****************************@phx.gbl... >> Hi Jan, >> >> Thanks! >> >> So do u mean that we have to go about the same old way of >> try-catch in this case? Any other way? >> >> Rakesh >> >> >> >> >-----Original Message----- >> >No, the unhandled exceptions on other threads wont be >> caught. >> > >> >-- >> >Greetz, >> >Jan >> >__________________________________ >> >Read my weblog: http://weblogs.asp.net/jan >> >"Rakesh" <an*******@discussions.microsoft.com> schreef >> in bericht >> >news:04****************************@phx.gbl... >> >> 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. >> >> >> >> But, suppose I create a new thread within my app and an >> >> unhandled exception is generated in that thread, will >> >> that exception be caught here? >> >> >> >> Thanks in advance, >> >> Rakesh >> >> >> > >> > >> >. >> > > > >. >
You aren't really catching them; think of it as a notification that one
occurred. It gives you an opportunity to provide some application-wide
policies (log it, notify someone via email, terminate the process, etc). If
you want to programmatically recover from it then you must wrap the callsite
throwing the exception in a try-catch block.
If you look at the fields in the UnhandledExceptionEventArgs the unhandled
exception handler gets, one of them is the flag I mentioned called
IsTerminating. This is a read-only property, which means that the runtime
itself is determining what will happen next and that it is too late to
recover from it.
If you hook the AppDomain.CurrentDomain.UnhandledException you will be
notified that the exception occurred but you will not be able to recover
from it within this method. I don't know what functionality you want to
provide so I do not know if this is suitable or not for you.
"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl... Hi Dave,
I want to know if i got you right:
So if i have only one appdomain and i attach an event handler in the AppDomain.CurrentDomain.UnhandledException, will that ensure that I can handle all the uncaught exceptions regardless of whichever thread they are in?
Rakesh -----Original Message----- You can attach a handler to the AppDomain.CurrentDomain.UnhandledExceptionevent, but be aware that one of its limitations is that it will only workfor the default appdomain.
If you create the thread yourself then you should put a try-catch blockwithin the thread's start function to ensure that you will catch and handleall exceptions. For the main thread and threads that originate in unmanagedcode, an unhandled exception will terminate the app. For threads you createmanually, threadpool threads, and finalizer threads, even though yourunhandled exception handler is called, the runtime will catch and swallowall exceptions; the IsTerminating field in the UnhandledExceptionEventArgsis set to false.
"Rakesh" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl... Hi Jan,
Thanks!
So do u mean that we have to go about the same old way of try-catch in this case? Any other way?
Rakesh >-----Original Message----- >No, the unhandled exceptions on other threads wont be caught. > >-- >Greetz, >Jan >__________________________________ >Read my weblog: http://weblogs.asp.net/jan >"Rakesh" <an*******@discussions.microsoft.com> schreef in bericht >news:04****************************@phx.gbl... >> 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. >> >> But, suppose I create a new thread within my app and an >> unhandled exception is generated in that thread, will >> that exception be caught here? >> >> Thanks in advance, >> Rakesh >> > > >. >
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anil K. Gupta |
last post by:
Hello,
I am developing an application similar to MSN Messenger using C#.Net.
I am using the Frameworks' System.Net.Sockets class for creating
sockets and then communicating.Everything seems to...
|
by: Robert Scheer |
last post by:
Hi.
I am using Application.ThreadException together with a sub to catch
unhandled exceptions on one form. My application has 4 forms. Do I
need to add an event handler for the...
|
by: Jason MacKenzie |
last post by:
I have a production critical windows forms application. I have try catch
blocks everywhere to handle every eventuality. However occasionally, every
couple of months, the application crashes. Its...
|
by: Lucas Tam |
last post by:
Without writing try/catch statements is there a way to have a global error
handler in VB.NET? In ASP.NET there is an application level error handler
inside Global.asax, but is there something...
|
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...
|
by: rs |
last post by:
Hi guys
Thank you in advance for the help. I developed a simple application
using vs.net 2003. running framework 1.1 sp1. the application runs fine
on the development machine (win xp). I tried...
|
by: paul.mason |
last post by:
I was wondering if anyone else had come across this "feature" of .NET
and if they had any idea what might be causing it.
I've been writing my first C# Windows application (so if there's
anything...
|
by: Shehab Kamal |
last post by:
In Main I register ThreadException to handle unhandled exceptions
Application.ThreadException += new
ThreadExceptionEventHandler(App_ThreadException);
The method will show a MessageBox or a Form...
|
by: Frank Rizzo |
last post by:
I have a c# 2.0 winform app that runs under a user account with very
limited rights. The application crashes on some actions (the Send Error
to Microsoft screen) with unauthorized exception.
...
|
by: giddy |
last post by:
hi,
I made this little crash reporter system for my project. It works by
getting hooked up to the Application.ThreadException event. If an
unhandled exception occurs , it logs it and then puts...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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,...
|
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: 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,...
| |