Error Handler for Forms rather than functions

Hi,

We can add an error handler to any of the functions routines, but what we are looking for is can we add a Error handler to a whole form.

The reason we want this we get a the same error message for many functions and would like to create a generic consolidated error handler for them.
RobKearneyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Hi RobKearney,

You can add a project wide exception catcher....

1) Go to Project Properties > Application tab
2) Ensure "Enable application framework" is checked.
3) Click the "View Application Events" button
4) Then in the "MyApplication" class, you can use this event....

    Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
        MsgBox(e.Exception.Message)
    End Sub

Regards,

Wayne
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MTEXXCommented:
Here's a way to do it.  I think there are much better ways; not cookie-cutter stamped into each class but rather a singleton log / error handler.  If it is needed to occur in a form, then you must have very specific business logic to deal with the errors, which would not be reusable.  Hence, it is custom code and there are really not any canned solutions.

At any rate- as you asked:
    ''' <summary>
    ''' Class-level exception handler.  Paste this in each class, and hardcode the MyClass name
    ''' </summary>
    ''' <param name="functionName">The name of the function generating the exception</param>
    ''' <param name="culprit">The offending function call and arguments</param>
    ''' <param name="ex">The exception caught.</param>
    ''' Example: in a try-catch block, 'Catch ex As Exception: handleExceptions("myFunctionName", "file.io.shred", ex)
    ''' <remarks></remarks>
    Private Sub handleExceptions(ByVal functionName As String, ByVal culprit As String, ByVal ex As Exception)
        'TODO mirror this to you log file, windows event log etc...
        Console.WriteLine("EXCEPTION in MyClass::" + functionName + "(" + culprit + ") " + ex.ToString)
    End Sub

Open in new window

0
RobKearneyAuthor Commented:
Kinda lost my focus on this, but as always am more than grateful for posts.

Can't confirm if solution for future searchers, but split points in recognition of posting in first place
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.