Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » To get xml errors from LoadFromXML
To get xml errors from LoadFromXML [message #37806] Wed, 14 November 2012 09:18 Go to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello all

Now it is not possible to get errors in XML strings detected by LoadFromXML() because they are catched inside and removed.

I would vote to remove the try-catch from LoadFromXML() and let the programmer to handle the error properly.

bool LoadFromXML(Callback1<XmlIO> xmlize, const String& xml)
{
	try {
		XmlNode node = ParseXML(xml);
		if(node.GetCount() == 0)
			return false;
		for(int i = 0; i < node.GetCount(); i++)
			if(node.Node(i).IsTag()) {
				Value dummy;
				xmlize(XmlIO(node.At(i), true, dummy));
				break;
			}
		return true;
	}
	catch(XmlError) {}    // XmlError is removed
	return false;
}


Best regards
IƱaki
Re: To get xml errors from LoadFromXML [message #37901 is a reply to message #37806] Wed, 21 November 2012 11:26 Go to previous messageGo to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
I agree with this. I am using this code as container for my application settings and when I alter my XML file to be wrong and start my application after, the application crashes after it reaches 2 GB memory usage. I would really like to catch the error that currently is suppressed there.
Re: To get xml errors from LoadFromXML [message #37913 is a reply to message #37901] Thu, 22 November 2012 22:45 Go to previous messageGo to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
I have found a temporary solution for this problem, would anybody need it:

bool LoadFromXML(Callback1<XmlIO> xmlize, const String& xml)
{
	try {
		XmlNode node = ParseXML(xml);
		if(node.GetCount() == 0)
			return false;
		for(int i = 0; i < node.GetCount(); i++)
			if(node.Node(i).IsTag()) {
				Value dummy;
				xmlize(XmlIO(node.At(i), true, dummy));
				break;
			}
		return true;
	}
	catch(XmlError x)
        {
            throw x;
        }    // XmlError is removed
	return false;
}


Now just use try-catch in your LoadFromXML call to handle the thrown error.

This works for now, and since most situations XML operations won't be performance critical this solution isn't a too bad one. However, in my opinion this should be fixed.
Re: To get xml errors from LoadFromXML [message #42107 is a reply to message #37913] Thu, 20 February 2014 08:53 Go to previous message
mirek is currently offline  mirek
Messages: 13132
Registered: November 2005
Ultimate Member
Only for reference purposes, if anybody finds this thread again, use

TryLoadFromXML

Mirek
Previous Topic: Xmlize default value
Next Topic: Bug: AString<B>::ReverseFind broken for wchar
Goto Forum:
  


Current Time: Mon Mar 01 01:56:22 CET 2021

Total time taken to generate the page: 0.01707 seconds