• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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.
0
RobKearney
Asked:
RobKearney
2 Solutions
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now