Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How do I resume Execution after I fix the error?

 

The failure I want to fix occures at gdsData.Tables("MyTable").NewRow(). The path the user took to get here resulted in no data loaded into the Dataset, so I want to load the dummy record into the dataset to allow the add to continue.


Try

 gdsData.Tables("MyTable").NewRow()
 gdsData.BeginEdit()
 ....

Catch oException As Exception

 If oException.Message = "Object reference not set to an instance of an object." then

   giCurrentDocID = 1
   funLoadDocData()
   Resume?

 Else

 'something else happened so bail out

 End if

End Try

 

After I load the Doc Data I want to resume where I left off in this instance.

Also is this the best way to handle the error or could there be a cleaner way to do this?

 

Thanks

MTS

"Beer is proof that God loves us and wants us to be happy."

-Benjamin Franklin

  • Administrators
Posted

Firstly you would be much better catching the specific exception rather than relying on the error message to identify the problem. Also it would be better if you only put the line that causes the exception in the try block.

. i.e.

Try

 gdsData.Tables("MyTable").NewRow()
Catch oException As NullReferenceException
   giCurrentDocID = 1
   funLoadDocData()
   Resume?
catch ex as Exception
   'Something else happened so deal with it here
End Try

gdsData.BeginEdit()
....

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • *Experts*
Posted

To prevent this exception from being thrown in the first place,

check to see if the object is equal to a null reference (Nothing)

before using it.

 

If MyObject Is Nothing Then
 ' The object wasn't initialized
Else
 ' The object can be used
End If

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Thanks,

 

I tried both methods Just for fun and they worked like a charm. I was looking at some old code and I had used the if odject is nothing then to fix it before so that is what I stuck with.

 

Thanks From a very stressed out under an impossible deadline programmer!

MTS

"Beer is proof that God loves us and wants us to be happy."

-Benjamin Franklin

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...