MTSkull Posted December 18, 2003 Posted December 18, 2003 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 Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
Administrators PlausiblyDamp Posted December 18, 2003 Administrators Posted December 18, 2003 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() .... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Bucky Posted December 18, 2003 *Experts* Posted December 18, 2003 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 Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
MTSkull Posted December 18, 2003 Author Posted December 18, 2003 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 Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.