By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,435 Members | 2,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,435 IT Pros & Developers. It's quick & easy.

Disable 'continue' option when an unhandled exception occurs?

P: n/a
Hi,

I feel like a noob for asking this.

When I publish a VB windows application, I want to disable the ability of
the the user to continue when there is an unhandled exception.

For example, if there is a bug in the program that causes an exception, I
want the program to crash. If there is an unhandled exception the program is
in an undefined state, and continuing could be dangerous. I'm surprised the
default is to give the user the option to continue, quite frankly. I'm using
Visual Studio 2005.

Thanks,
-SurturZ

Jul 17 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
surturz wrote:
When I publish a VB windows application, I want to disable the ability of
the the user to continue when there is an unhandled exception.
Simple answer - don't leave any exceptions unhandled.
If you do, then control passes over to the user and there's /nothing/
you can do to stop them hitting the "Continue" button.
For example, if there is a bug in the program that causes an exception, I
want the program to crash.
Yes, but not as "far" as that appalling "Oops" dialog.

Add a handler for Application.ThreadException and clean things up in
there. Show the user a sanitised message (in,say, a MessageBox) and
then take the application down completely.

Oh, and watch out for Threads as well; in VB'2005, if an Exception
"escapes" from one of your [background] Threads, it will take the entire
application down with it.
I'm surprised the default is to give the user the option to continue,
quite frankly.
I couldn't agree more. The application will probably be in a really bad
way at this point and to give a user the option to say "Oh well, that
error doesn't matter" is just terrifying.

HTH,
Phill W.
Jul 17 '07 #2

P: n/a
Hi SurturZ,

Thank you for the feedback.

I am not sure if Winform team will remove this continue button in Orcas.
Actually, the Winform team highly recommended the developer to provide a
customized ThreadException handler, so that they can fully control the
crash logic themselves. The reason that the "Continue" button is on by
default is some developers requested this feature for debugging purpose.

Anyway, if you need any further help or have any concern, please feel free
to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 18 '07 #3

P: n/a
Open the project properties. On the "Application" tab, you click the "View
Application Events" button. That will generate a new partial class looking
like this:

Namespace My

' The following events are availble for MyApplication:

'

' Startup: Raised when the application starts, before the startup form is
created.

' Shutdown: Raised after all application forms are closed. This event is not
raised if the application terminates abnormally.

' UnhandledException: Raised if the application encounters an unhandled
exception.

' StartupNextInstance: Raised when launching a single-instance application
and the application is already active.

' NetworkAvailabilityChanged: Raised when the network connection is
connected or disconnected.

Partial Friend Class MyApplication

End Class

End Namespace
Create a handler like this in the MyApplication class:

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e
As Microsoft.VisualBasic.ApplicationServices.Unhandle dExceptionEventArgs)
Handles Me.UnhandledException

'My.Application.Log.WriteException(e.Exception, TraceEventType.Critical,
"Unhandled Exception.")

MsgBox("An unhandled exception occurred: " & e.Exception.Message &
vbCrLf & vbCrLf & "I'm going to quit now!")

End

End Sub

That should do it.

Cheers,
Johnny J.

"surturz" <su*****@newsgroup.nospamwrote in message
news:FF**********************************@microsof t.com...
Hi,

I feel like a noob for asking this.

When I publish a VB windows application, I want to disable the ability of
the the user to continue when there is an unhandled exception.

For example, if there is a bug in the program that causes an exception, I
want the program to crash. If there is an unhandled exception the program
is
in an undefined state, and continuing could be dangerous. I'm surprised
the
default is to give the user the option to continue, quite frankly. I'm
using
Visual Studio 2005.

Thanks,
-SurturZ

Jul 18 '07 #4

P: n/a
UnhandledExceptionEventArgs.ExitApplication Property in ApplicationEvents.vb
under VS2005 gives you the ability to not continue

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e
As Microsoft.VisualBasic.ApplicationServices.Unhandle dExceptionEventArgs)
Handles Me.UnhandledException

' Do your recovery like write to a log file followed by

e.ExitApplication = True

End Sub

"surturz" <su*****@newsgroup.nospamwrote in message
news:FF**********************************@microsof t.com...
Hi,

I feel like a noob for asking this.

When I publish a VB windows application, I want to disable the ability of
the the user to continue when there is an unhandled exception.

For example, if there is a bug in the program that causes an exception, I
want the program to crash. If there is an unhandled exception the program
is
in an undefined state, and continuing could be dangerous. I'm surprised
the
default is to give the user the option to continue, quite frankly. I'm
using
Visual Studio 2005.

Thanks,
-SurturZ

Jul 18 '07 #5

P: n/a
Hi SurturZ,

Have you reviewed my last reply to you? If you still have anything unclear,
please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.