Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > VB application exceptions give the option to continue
 

VB application exceptions give the option to continue

When a VB 2008Express Editionapplication comes upon an exception, it givesthe user the options ofContinue or Quit. Is it possible to remove the Continue option, so that a user will not accidentally press it?
lineandcircle  Thursday, April 30, 2009 12:11 AM
Or, since this is VB, you can use the built-in functionality for a global exception handler:

1. Double-click on My Project in a windows forms VB project.

2. Click on the Application tab.

3. Click on theView Application Events button.

4. Select MyApplication Events from the left drop-down.

5) Select UnhandledException from the right drop-down.

6) Add any desired code. Something like this will work:

       Private Sub MyApplication_UnhandledException( _
           ByVal sender As Object, _
           ByVal e As Microsoft.VisualBasic.ApplicationServices. _
           UnhandledExceptionEventArgs) _
           Handles Me.UnhandledException
            ' Add logging here

            ' And display a message to the user
            MessageBox.Show("The application could not process your request so it is shutting down. Please see your administrator")
        End Sub
Hope this helps.
www.insteptech.com
DeborahK  Thursday, April 30, 2009 7:40 PM

Best Practice is to never allow any system (that is VB Express) messages to appear to the user.

You can use Try/Catch blocks to catch any errors and display your own messages and/or log the problem to a file so you can later see what happened. (That way the users don't have to tell you what the message said, you will have it in the log file.)

Here is a link to more information:

http://msdn.microsoft.com/en-us/library/8a9f2ew0(VS.80).aspx


www.insteptech.com
DeborahK  Thursday, April 30, 2009 3:28 PM
As said already, try to use try catch blocks everywhere in the code where you suspect an exception will be thrown. You could also use a globalexceptionhandler to handle all the exceptions thrown in your application in one place.

___________________________________________ If this post is useful, mark it as answer.
CodeCruiser  Thursday, April 30, 2009 4:02 PM
Do you know how to set up a global exception handler in VB 2005?
lineandcircle  Thursday, April 30, 2009 7:26 PM
Use this statement in the main form load event

AddHandler
 System.AppDomain.CurrentDomain.UnhandledException, _
AddressOf UnhandledExceptionHandler

Then define the UnhandledExceptionHandler as a sub.
___________________________________________ If this post is useful, mark it as answer.
CodeCruiser  Thursday, April 30, 2009 7:31 PM
AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler


AddHandler System.AppDomain.CurrentDomain.UnhandledException, _
                                      AddressOf UnhandledExceptionHandler

Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Thursday, April 30, 2009 7:34 PM
A useful article for reference

http://www.devcity.net/Articles/60/1/unhandled_exceptions.aspx

Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Thursday, April 30, 2009 7:37 PM
Or, since this is VB, you can use the built-in functionality for a global exception handler:

1. Double-click on My Project in a windows forms VB project.

2. Click on the Application tab.

3. Click on theView Application Events button.

4. Select MyApplication Events from the left drop-down.

5) Select UnhandledException from the right drop-down.

6) Add any desired code. Something like this will work:

       Private Sub MyApplication_UnhandledException( _
           ByVal sender As Object, _
           ByVal e As Microsoft.VisualBasic.ApplicationServices. _
           UnhandledExceptionEventArgs) _
           Handles Me.UnhandledException
            ' Add logging here

            ' And display a message to the user
            MessageBox.Show("The application could not process your request so it is shutting down. Please see your administrator")
        End Sub
Hope this helps.
www.insteptech.com
DeborahK  Thursday, April 30, 2009 7:40 PM

You can use google to search for other answers

Custom Search

More Threads

• Too many arguments
• datagrid combox question
• Why don't we have pointers?
• need help porting Visual Basic method call to C#
• AppendText & Text
• Collectionbase problem : "Windows Form Designer Generated Code" is/seems incorrect
• Changing tab browsing order!
• Click on a button in the browser to open another new window
• Enumerating all referenced assemblies for a specific assembly
• Form vs secondary thread problem