473,407 Members | 2,314 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,407 software developers and data experts.

Exceptions dont "bubble up" in standalone EXE, but DO in the Visual Studio mode

Hi all. In my program I try to handle all obvious potential errors with
structured error handling (try-catch) block. What I would like to do is
have an 'overall' error handler that would gracefully catch any
unanticipated errors. I created a startup module to place my overall error
handling for my "real" program which is Form1. My program is structured
like this:

Module startup

..

public sub Main()

.. try

.. application.run(new Form1) 'this is line 45 of module startup

..catch ex as exception

msgbox(ex.tostring)

end try

end sub

end module

Within the Form1 application I put a button that, when clicked, throws an
exception:

Button1Click

Throw new exception("error occurred") 'this is line 899 of Form1

Here's the problem. When I run inside the VisualStudio environment the
exception works exactly as I would expect. That is, my messagebox displays
the full stack trace pointing to line 899 of form1 and 45 of startup.
Again, this is what I would expect.

However, when I build the appl and run it standalone, the same button
displays a popup window that says it is an unhandled exception, and does not
give stack trace info.

Here's the good part.. if I put the "Throw new exception" into a Try-Catch
block then when I run it standalone it DOES give me stack trace info. So,
it seems like when I run it as a standalone exe the exception does not
"bubble up" to the next higher level of error handling as I think it should.

Can anybody shed some light on this behavior? Thanks.
Nov 21 '05 #1
2 2330
Hi John

Try adding this Event handler to your startup code:
AddHandler Application.ThreadException, AddressOf Bla

And then you will get unhandled exceptions in the Exception property of your
ThreadExceptionEventArgs object.

Public Sub Bla(ByVal sender As Object, ByVal e As
System.Threading.ThreadExceptionEventArgs)

End Sub

HTH

Nigel

"JohnR" wrote:
Hi all. In my program I try to handle all obvious potential errors with
structured error handling (try-catch) block. What I would like to do is
have an 'overall' error handler that would gracefully catch any
unanticipated errors. I created a startup module to place my overall error
handling for my "real" program which is Form1. My program is structured
like this:

Module startup

..

public sub Main()

.. try

.. application.run(new Form1) 'this is line 45 of module startup

..catch ex as exception

msgbox(ex.tostring)

end try

end sub

end module

Within the Form1 application I put a button that, when clicked, throws an
exception:

Button1Click

Throw new exception("error occurred") 'this is line 899 of Form1

Here's the problem. When I run inside the VisualStudio environment the
exception works exactly as I would expect. That is, my messagebox displays
the full stack trace pointing to line 899 of form1 and 45 of startup.
Again, this is what I would expect.

However, when I build the appl and run it standalone, the same button
displays a popup window that says it is an unhandled exception, and does not
give stack trace info.

Here's the good part.. if I put the "Throw new exception" into a Try-Catch
block then when I run it standalone it DOES give me stack trace info. So,
it seems like when I run it as a standalone exe the exception does not
"bubble up" to the next higher level of error handling as I think it should.

Can anybody shed some light on this behavior? Thanks.

Nov 21 '05 #2
Hi Nigel,

Yep, that worked great! Thanks so much for your help.

I still wonder why the TRY-CATCH block worked while in the VisualStudio
environment, but didn't in the standalone EXE. Since the threadexception
handler you suggested worked, this is sort of an academic question... But
for my general knowledge of VS and VB I sure would like to know why....
If anybody has the answer, please let me know...

Again, thanks,
John
"Nigel Armstrong" <ni****@newsgroups.nospam> wrote in message
news:5A**********************************@microsof t.com...
Hi John

Try adding this Event handler to your startup code:
AddHandler Application.ThreadException, AddressOf Bla

And then you will get unhandled exceptions in the Exception property of
your
ThreadExceptionEventArgs object.

Public Sub Bla(ByVal sender As Object, ByVal e As
System.Threading.ThreadExceptionEventArgs)

End Sub

HTH

Nigel

"JohnR" wrote:
Hi all. In my program I try to handle all obvious potential errors with
structured error handling (try-catch) block. What I would like to do is
have an 'overall' error handler that would gracefully catch any
unanticipated errors. I created a startup module to place my overall
error
handling for my "real" program which is Form1. My program is structured
like this:

Module startup

..

public sub Main()

.. try

.. application.run(new Form1) 'this is line 45 of module startup

..catch ex as exception

msgbox(ex.tostring)

end try

end sub

end module

Within the Form1 application I put a button that, when clicked, throws an
exception:

Button1Click

Throw new exception("error occurred") 'this is line 899 of Form1

Here's the problem. When I run inside the VisualStudio environment the
exception works exactly as I would expect. That is, my messagebox
displays
the full stack trace pointing to line 899 of form1 and 45 of startup.
Again, this is what I would expect.

However, when I build the appl and run it standalone, the same button
displays a popup window that says it is an unhandled exception, and does
not
give stack trace info.

Here's the good part.. if I put the "Throw new exception" into a
Try-Catch
block then when I run it standalone it DOES give me stack trace info.
So,
it seems like when I run it as a standalone exe the exception does not
"bubble up" to the next higher level of error handling as I think it
should.

Can anybody shed some light on this behavior? Thanks.

Nov 21 '05 #3

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

Similar topics

57
by: John Howard | last post by:
I've sent several messages over the last year asking about python - Who teaches python? Is python losing steam? etc. I have noticed, eg, the declinng number of books at my local borders. The last...
3
by: Robert Oschler | last post by:
I have an IFrame on my web pages that displays useful tips. I have a button next to it that hides and shows it by triggering a Javascript call. I know how to make the iframe invisible by changing...
3
by: JohnEGee | last post by:
Hello, all, and TIA for any help you can offer. I've searched the Internet for answers and have finally come here. I've created a page (several, actually) with a link that opens a pop-up...
2
by: Alienz | last post by:
Lets say I have a form called Planet_Systems and a form called Species. I then want to link the primary key "Planet" to bring up it's various species in the corresponding subform. So, I created a...
3
by: Travis | last post by:
I am trying to prevent an exception from bubbling up from one nested Try/Catch Block to its "Parent" Try/Catch Block. Here is some example code: try{ try{ //Non-application killing code that...
0
by: Matthew Belk | last post by:
I am trying to print some 2x6 labels on a SATO CL408e thermal label printer. The 2x6 labels are arranged in "landscape" mode with 2 labels per "sheet." When I attempt to print "x" copies of a 1...
5
by: dpomt | last post by:
When the ASP.NET menu is rendered on downlevel browers, the text "^ up one level" is displayed. Any ideas how I can change that text? I did not find a property for the menu control where I can...
1
by: vincehallam | last post by:
Hi newby here sorry if this sounds bread and butter stuff. Using MS Access 2003 On a Form I want two Combo boxes which are getting their data from a table. The Combo boxes are A "Price 1" & B...
5
by: JamesX | last post by:
I am having trouble detecting if "down" or "up" key is pressed within a textbox. Evidently those keys do not fire the "KeyPressed" event. Does anyone know how to detect when they are pressed?
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: 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...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.