473,585 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unhandled Exception within a try catch

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 operations
are all within Try Catches to help me locate the problem and the origination
of any problem by specifiying an error code in the "Catch" section.
So theoretically this shouldn't have been possible (at which point we all
say "yeah, right...."(in a sarcastic manner)). However.......

I get the data files from the client and try to run those files in my
install (from an .msi) of the application. I get the same unhandled
exception.
However when I then run the program within Visual Studio (which has not been
changed since the .msi was produced) I don't get an unhandled error. I get
my error code instead!

The call originates in a seperate thread, this thread fires an event which a
form has subscribed to. The form eventhandler calls the data object which is
stored within a .dll and initiates the process that causes the exception.
The method in the seperate thread where the event is fired is Try Catched,
the method in the form that utilises the data object is Try Catched. The
method within the data object itself is NOT Try-Catched.

Is it the case that VS studio is hiding the true results of such an
exception? If a thread executes a method in a .dll and the .dll method calls
throws an exception will that not be caught by a Try Catch in the
originating method?

Please advise, as this confuses the hell out of me.

Nov 25 '05 #1
5 3378
In Visual Studio (Tools -> Options -> Debugging -> Inbreak mode, only stop
execution of the current process)

This check box makes me feel like Visual Studio stops all running processes
by default.
And so It handles the exceptions differently than the released version.
It is just a guess ofcourse...

--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"Simon Tamman {Uchiha Jax}" wrote:
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 operations
are all within Try Catches to help me locate the problem and the origination
of any problem by specifiying an error code in the "Catch" section.
So theoretically this shouldn't have been possible (at which point we all
say "yeah, right...."(in a sarcastic manner)). However.......

I get the data files from the client and try to run those files in my
install (from an .msi) of the application. I get the same unhandled
exception.
However when I then run the program within Visual Studio (which has not been
changed since the .msi was produced) I don't get an unhandled error. I get
my error code instead!

The call originates in a seperate thread, this thread fires an event which a
form has subscribed to. The form eventhandler calls the data object which is
stored within a .dll and initiates the process that causes the exception.
The method in the seperate thread where the event is fired is Try Catched,
the method in the form that utilises the data object is Try Catched. The
method within the data object itself is NOT Try-Catched.

Is it the case that VS studio is hiding the true results of such an
exception? If a thread executes a method in a .dll and the .dll method calls
throws an exception will that not be caught by a Try Catch in the
originating method?

Please advise, as this confuses the hell out of me.

Nov 25 '05 #2
Simon,

I don't have an answer for your question, but I want you to consider that
there is one special group of exception - OutOfMemoryExce ption,
StackOverflowEx ception and ExceutionEnglin eException that should be treated
in a special way. What makes them unique is that they are not thrown by
framework's or users code, but rather from the CLR itself when something
goes wrong and the state of the runtime engine is not stable.

Depending on the circumstances when one of these is thrown, it might be even
not possible to catch it. Even more it is most likely that when such
exception is thrown the *finally* blocks in the code (if any) are not going
to execute. This is because, for example in a case of stack overflow, in
order to prepare and throw the exception as well as for the code to catch
and recover from it more stack space could be required. CLR may find
possible to discover stack overflow situations before it runs out of stack
memory and in this case it will throw an exception that can be caught. If
the guard page for the stack gets overridden. that's it, the CLR throws an
exception and terminates the application and no handlers are executed.

Because of this even if the code caches such exception the code should never
try to recover from it. It should log the exception and terminate the
application.

The only sure thing that can be used to catch stack overflow is to install
Windows SEH handler. Since v2.0 .NET framework provides a class that can be
used to install such cases - RuntimeHelpers.

For more info I'd suggest reading the following article.

http://msdn.microsoft.com/msdnmag/is...0/Reliability/

Why you can handle the exception in your machine, but on the client machine
it shows up as unhandled I guess it is because of different runtime
environments. For example you may have more memory installed that the user.
It is just a wild guess though.


HTH

Stoitcho Goutsev (100) [C# MVP]

"Simon Tamman {Uchiha Jax}"
<i_************ *************** *******@NOSPAMh otmail.com> wrote in message
news:oe******** ********@newsfe 7-gui.ntli.net...
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
operations
are all within Try Catches to help me locate the problem and the
origination
of any problem by specifiying an error code in the "Catch" section.
So theoretically this shouldn't have been possible (at which point we all
say "yeah, right...."(in a sarcastic manner)). However.......

I get the data files from the client and try to run those files in my
install (from an .msi) of the application. I get the same unhandled
exception.
However when I then run the program within Visual Studio (which has not
been
changed since the .msi was produced) I don't get an unhandled error. I get
my error code instead!

The call originates in a seperate thread, this thread fires an event which
a
form has subscribed to. The form eventhandler calls the data object which
is
stored within a .dll and initiates the process that causes the exception.
The method in the seperate thread where the event is fired is Try Catched,
the method in the form that utilises the data object is Try Catched. The
method within the data object itself is NOT Try-Catched.

Is it the case that VS studio is hiding the true results of such an
exception? If a thread executes a method in a .dll and the .dll method
calls
throws an exception will that not be caught by a Try Catch in the
originating method?

Please advise, as this confuses the hell out of me.

Nov 25 '05 #3
Oh yes, stupidity is as always the answer.

If an exception happens write it in the error log.---------------

void WriteError(Exce ption ex, string errorCode)
{
CheckFileSize(C onstants.ErrorL og);
WriteToLog(ex, errorCode);
MessageBox.Show (errorCode);
}

CheckFileSize(s tring path)
{
try
{
FileInfo fi = new FileInfo(path);
if(fi.Length>0)
{
int kb = fi.Length/1024;
if(bk>1024)
{
fi.Delete();
}
}
}
catch(Exception ex)
{
WriteError();
}
}

Instant StackOverFlow because I didn't check to see if the fileInfo exists
(hence if it doesn't it throws an exception which makes it checkagain and
round and round).
Now that's stupid.

This error didn't occur on my machine because the log was already there. On
a client machine it hadn't been created yet.
Thanks for your help and sorry for wasting your time with my foolishness. I
at least hope you got a giggle out of it.
"Simon Tamman {Uchiha Jax}"
<i_************ *************** *******@NOSPAMh otmail.com> wrote in message
news:oe******** ********@newsfe 7-gui.ntli.net...
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 operations are all within Try Catches to help me locate the problem and the origination of any problem by specifiying an error code in the "Catch" section.
So theoretically this shouldn't have been possible (at which point we all
say "yeah, right...."(in a sarcastic manner)). However.......

I get the data files from the client and try to run those files in my
install (from an .msi) of the application. I get the same unhandled
exception.
However when I then run the program within Visual Studio (which has not been changed since the .msi was produced) I don't get an unhandled error. I get
my error code instead!

The call originates in a seperate thread, this thread fires an event which a form has subscribed to. The form eventhandler calls the data object which is stored within a .dll and initiates the process that causes the exception.
The method in the seperate thread where the event is fired is Try Catched,
the method in the form that utilises the data object is Try Catched. The
method within the data object itself is NOT Try-Catched.

Is it the case that VS studio is hiding the true results of such an
exception? If a thread executes a method in a .dll and the .dll method calls throws an exception will that not be caught by a Try Catch in the
originating method?

Please advise, as this confuses the hell out of me.

Nov 25 '05 #4
> I get the data files from the client and try to run those files in my
install (from an .msi) of the application. I get the same unhandled
exception.
However when I then run the program within Visual Studio (which has not been
changed since the .msi was produced) I don't get an unhandled error. I get
my error code instead!


I don't remembre the gory details, but the upshot is that calls /
events within a WinForms app are handled differently under the debugger
than when running directly under Windows.

When you run the app under the debugger, all calls to event delegates
proceed as you would expect: the event is raised and the event handlers
are called one by one directly from the point at which the event is
raised.

Under Windows, under some circumstances that I can't recall, certain
events cause a return to the Windows message loop, which then calls the
event delegates directly. (Or something like that... I'm probably
making a mess of this explanation.)

The bottom line is that when you run your WinForms application directly
rather than under the debugger, you will notice on your stack dumps
that methods that you thought were being called from events in your
code are in fact being called directly from the O/S. So, when the
method in question bombs, the try...catch in your own code doesn't
catch the exception because the call isn't being made from your code,
it's being made directly from Windows.

The only way to catch these exceptions is by subscribing to
AppDomain.Unhan dledException and Application.Thr eadException events.

Nov 25 '05 #5
Simon Tamman {Uchiha Jax}
<i_************ *************** *******@NOSPAMh otmail.com> wrote:

<snip>
Thanks for your help and sorry for wasting your time with my foolishness. I
at least hope you got a giggle out of it.


It's never a waste of time when an explanation is presented afterwards.
Someone may well have a similar problem, find your post, and get an
idea of where to go.

It's *much* better than the "It's all right, I've fixed it" posts we
sometimes get which don't say anything about what was wrong.

So thanks, and best of luck with the rest of the project :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '05 #6

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

Similar topics

4
2240
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited...
4
2398
by: Frank | last post by:
Hi, I made a handler for unhandled errors. But before that is executed, VB.NET gives me the standard error window. In VB6 there was a setting (errortrapping) about handling errors in the design environment and classes, which should prevent the before mentioned behaviour. Does VB.NET have a setting like it? Or is there something else? ...
5
5733
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the...
5
3000
by: mattiassich | last post by:
The following code causes unhandled exception on the line: New ManagementObjectSearcher(query) Dim mos As System.Management.ManagementObjectSearcher Dim moc As System.Management.ManagementObjectCollection Dim mo As System.Management.ManagementObject Dim query As String = "SELECT * FROM Win32_OperatingSystem" mos = New...
5
3290
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the...
0
1975
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 about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason...
3
1811
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 Exception <<< Here!
15
2316
by: Mark Lewis | last post by:
I have a weird error trapping problem. When running the IDE everything works fine but not when running in an EXE I get the Unhandled Exception Error message box intead of the one in my Try....Catch Block. To see this create a simple application with two forms. Form 1 should have one button. The code is follows. Run this in the IDE and...
4
6895
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in...
0
8195
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7947
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8209
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6596
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2340
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.