-
May 11th, 2009, 03:18 PM
#1
Thread Starter
Hyperactive Member
Error fires off yet ex is nothing?
Im parsing through a xml file and a error is thrown and the event is fired off but the exception is still nothing even though it tells me theres an exception. :S
VB.net Code:
Friend Event XMLError(ByVal ex As Exception)
Friend Function ReadXML(ByVal XML As String) As Boolean
Try
Catch ex As Exception
RaiseEvent XMLError(ex)
Return False
End Try
End Function
Thats how the code is set up. It is enclosed inside a try statement to catch the error but when the event is raised "ex" is nothing.
The event is handled on my form like so:
vb.net Code:
#Region "Events"
Private WithEvents _xml As ReadXML
#End Region
Private Sub XMLError(ByVal ex As Exception) Handles _xml.XMLError
MsgBox(ex, MsgBoxStyle.Critical, "Error")
End Sub
Any idea what the problem is?
-
May 11th, 2009, 04:49 PM
#2
Re: Error fires off yet ex is nothing?
Where's the code in the TRY statement? There's nothing for it to try.
-
May 11th, 2009, 05:51 PM
#3
Thread Starter
Hyperactive Member
Re: Error fires off yet ex is nothing?
vb Code:
Friend Function ReadXML(ByVal XML As String) As Boolean Try If Not IO.File.Exists(XML) Then RaiseEvent ErrorOccured("Version File cannot be found!") Dim m_xmlr As XmlTextReader = New XmlTextReader(XML) m_xmlr.WhitespaceHandling = WhitespaceHandling.None m_xmlr.Read() m_xmlr.Read() While Not m_xmlr.EOF m_xmlr.Read() If Not m_xmlr.IsStartElement() Then Exit While End If Version = m_xmlr.GetAttribute("Version") m_xmlr.Read() Server = m_xmlr.ReadElementString("Server") Server_pwprt1 = m_xmlr.ReadElementString("Password") End While RaiseEvent Completed(Version, Server, Server_pwprt1) Return True Catch ex As Exception RaiseEvent XMLError(ex) Return False End Try End Function
I deliberately wrote the xml file so that it would throw an exception while trying to reading it.
-
May 11th, 2009, 06:17 PM
#4
Re: Error fires off yet ex is nothing?
That makes sense, and has been done before (Error 0: completed, etc.)
Although if a true exception does occur, then EX should not be nothing. I don't see anything inherently wrong with your code that would make it throw an exception that's nothing.
-
May 11th, 2009, 10:03 PM
#5
Thread Starter
Hyperactive Member
Re: Error fires off yet ex is nothing?
Me either. It has me perplexed at the moment. Heres a screenshot of it throwing the exception:
And here it says ex is nothing:
Ive changed the exception to catch XMLException but that doesn't work either.
Edit:
I went and added Msgbox(ex.Message) and it fired it fine with the message but when in the handler for the error occured when i change it to ex.Message same error. What could be preventing it?
Last edited by youngbucks; May 11th, 2009 at 10:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|