cimperia Active Member Licensed User Longtime User Jul 29, 2019 #1 Here's a general question about XmlSax. How do you recover from error, or more exactly how do you stop processing when an exception is raised? More specifically, if an exception is raised in _StartElement or _EndElement procedures, you can try/catch the exceptions, but it does not stop the processing all together and the two subs will be called until the end of the stream. It's obviously no good to wrap the call to parser.Parse in a try/catch block as the exception won't be relayed. So, to reiterate, how do you stop the processing when an exception is raised? Thank you. Last edited: Mar 9, 2020
Here's a general question about XmlSax. How do you recover from error, or more exactly how do you stop processing when an exception is raised? More specifically, if an exception is raised in _StartElement or _EndElement procedures, you can try/catch the exceptions, but it does not stop the processing all together and the two subs will be called until the end of the stream. It's obviously no good to wrap the call to parser.Parse in a try/catch block as the exception won't be relayed. So, to reiterate, how do you stop the processing when an exception is raised? Thank you.
Erel B4X founder Staff member Licensed User Longtime User Jul 29, 2019 #2 An uncaught exception should stop the parsing. Tip: Use Xml2Map instead of parsing the XML yourself. Upvote 0
cimperia Active Member Licensed User Longtime User Jul 29, 2019 #3 Well, yes it's true that letting the exception uncaught will stop the parsing, but then there's no way to recover cleanly, is there? I had a look at Xml2Map and I wanted to avoid using it as my SmlSax routines are working just fine, until the data started to get rather dirty that is. Upvote 0
Well, yes it's true that letting the exception uncaught will stop the parsing, but then there's no way to recover cleanly, is there? I had a look at Xml2Map and I wanted to avoid using it as my SmlSax routines are working just fine, until the data started to get rather dirty that is.
Erel B4X founder Staff member Licensed User Longtime User Jul 29, 2019 #4 Code: Try Parser.Parse(...) Catch Log("Error occurred: " & LastException) End Try Upvote 0
cimperia Active Member Licensed User Longtime User Jul 29, 2019 #5 No that won't work. I tried that and the exception is not relayed back, so to speak. More precisely, if the exception is not handled in the _Start _End routine, then only Application_Error will be triggered. Upvote 0
No that won't work. I tried that and the exception is not relayed back, so to speak. More precisely, if the exception is not handled in the _Start _End routine, then only Application_Error will be triggered.
Erel B4X founder Staff member Licensed User Longtime User Jul 29, 2019 #6 In that case you will need to add Try / Catch blocks in the two events and you can use a global flag variable to stop processing following events. Upvote 0
In that case you will need to add Try / Catch blocks in the two events and you can use a global flag variable to stop processing following events.
cimperia Active Member Licensed User Longtime User Jul 29, 2019 #7 It's what I did. I used a global fail flag, but it's not very nice though. It stops the elements being processed but the _Start and _End Subs are still called for every element until the end of the stream. Anyway, thank you for your input. I reckon that the XmlSax implementation requires some more work to make it more user friendly. I'll see how much effort there is in rewriting my routines with Xml2Map . Last edited: Jul 29, 2019 Upvote 0
It's what I did. I used a global fail flag, but it's not very nice though. It stops the elements being processed but the _Start and _End Subs are still called for every element until the end of the stream. Anyway, thank you for your input. I reckon that the XmlSax implementation requires some more work to make it more user friendly. I'll see how much effort there is in rewriting my routines with Xml2Map .