By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,375 Members | 3,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,375 IT Pros & Developers. It's quick & easy.

How to handle System.NullReferenceException??

100+
P: 111
hii all,

im a fresher, and new to the programming side..
when im trying to execute a project...
m getting an exception at the line : If MyDocument.length=0


the code goes on like this:

Public Function MyGet(ByVal MyKey As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode
Dim XmlRoot As XmlNode
Dim XmlKey As XmlNode
Dim XmlValue As XmlNode

exception--->> If DocumentName.Length = 0 Then
Return ""
Exit Function
End If

XmlDocument.Load(MyDocument)
XmlNode = XmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings/add[@key=""" & MyKey & """]")

If XmlNode Is Nothing Then
'
' The node does not exist, let's create it
'
MyGet = ""

Else
'
' The node exist, save the new value
'
MyGet = XmlNode.Attributes.GetNamedItem("value").Value

End If
XmlDocument.Save(MyDocument)
XmlDocument = Nothing

Return MyGet

End Function



now can u tell me the solution...

thnks all...
Apr 25 '07 #1
Share this Question
Share on Google+
2 Replies


shweta123
Expert 100+
P: 692
Hi,

Put the whole code under
Try

catch ex as Exception
''''''''''you can get here exception message ,source etc.
msgbox(ex.Message)
msgbox(ex.Source)

end Try
Apr 25 '07 #2

radcaesar
Expert 100+
P: 759
If DocumentName.Length == 0

Check whether it returns NULL by DEBUG the code. Put break point and Watch it.
Apr 25 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.