?
Solved

Errorr trap

Posted on 2007-07-26
4
Medium Priority
?
285 Views
Last Modified: 2010-04-23
Hi Experts

I am debugging a project and have trapped an error when a form closes, I wish to clear the error and continue closing the form?

Dim objMap As MapPoint.Map
        objMap = Me.AxMappointControl1.ActiveMap
        Try
            objMap.Saved = True
        Catch ex As Exception
            If Err.Number = 91 Then
                Err.Clear()
                Exit Sub
            End If
            MsgBox(Err.Number & " " & Err.Description)
        End Try

The immediate window still reports a null error:

A first chance exception of type 'System.NullReferenceException' occurred

 The null error is created (I think) because the ax has not been used, is this poor practice, and should I save the ax control at another stage?

Regards,
Joe
0
Comment
Question by:JoeBo747
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:DarkoLord
ID: 19579245
Why do you need to clear the error? If that is happening on the form's unload event, you can use something like this:

Dim objMap As MapPoint.Map
        objMap = Me.AxMappointControl1.ActiveMap
        Try
            objMap.Saved = True
        Catch ex As Exception
            If Err.Number <> 91 Then MsgBox(Err.Number & " " & Err.Description)
        End Try
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 19580704
Hi DarkoLord:

My code traps the error and closes cleanly, I am new to vb.net and I don't know if leaving this as is; is good enough to cope with this scenario. When I publish the project could this situation cause problems for future users of my application?

Regards,
Joe
0
 
LVL 22

Accepted Solution

by:
DarkoLord earned 1000 total points
ID: 19581005
Hi,

it should work fine, however in such cases, checking if the variable is null (Nothing in VB) is considered a better approach:

Dim objMap As MapPoint.Map
objMap = Me.AxMappointControl1.ActiveMap
If Not objMap Is Nothing Then
      objMap.Saved = True
End If

Error trapping is supposed to be used to handle only the errors which you cannot predict when designing the application (database, network, file IO exceptions, ...).
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 19581034
Hi Darkolord

Thanks for the advice. Very useful

Regards,
Joe
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question