xmlbeansxx icon indicating copy to clipboard operation
xmlbeansxx copied to clipboard

Disable exceptions

Open Vanuan opened this issue 14 years ago • 5 comments

I'm trying to port xmlbeansxx to the system where exceptions are not available. So, I need to replace exceptions with return value. Do you have any suggestions? Where should I start?

Vanuan avatar Oct 04 '11 11:10 Vanuan

This can be problematic, but what do you mean with: "replace exceptions with return value" do you want something similar to XPCOM ?

for example a getContacts looks like this (XPCOM code): nsresult ContactBook::GetContacts(nsIArray **aContacts) { ... some code .... return NS_OK; }

the return value (contact list) is the last parameter and the nsresult is a error code.

or do you want just ignore all errors ?

in xmlbeansxx you have getters and setters like in java xmlbeans.

2011/10/4 John Yani < [email protected]>

I'm trying to port xmlbeansxx to the system where exceptions are not available. So, I need to replace exceptions with return value. Do you have any suggestions? Where should I start?

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/4

stawel avatar Oct 04 '11 12:10 stawel

Yes, I mean that instead of throwing an exception somewhere in

ContactBook::Factory::parse();

I want parse method return BeansException, so I could write

BeansException error = ContactBook::Factory::parse("...");
if(error.getType() != BeansException::OK)
{
    // handle error
}
else
{
    // use parsed object
}

Vanuan avatar Oct 04 '11 12:10 Vanuan

it is very difficult to implement. You have to rewrite the entire code generator.

It would be easier to remember all "throws" in a static table and return empty xmlbeansxx objects. something like this:

ContactBook c = ContactBook::Factory::parse("..."); if(BeansException::getError() != BeansException::OK) { // handle error } else { // use parsed object }

I'm also not sure if you can use xercesc without exceptions.

2011/10/4 John Yani < [email protected]>

Yes, I mean that instead of throwing an exception somewhere in

ContactBook::Factory::parse();

I want parse method return BeansException, so I could write

BeansException error = ContactBook::Factory::parse("..."); if(error.getType() != BeansException::OK) { // handle error } else { // use parsed object }

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/4#issuecomment-2285780

stawel avatar Oct 04 '11 13:10 stawel

Thanks for advice!

I saw that there is XmlParser class from which XercesParser and LibXMLParser are inherited. Can I use LibXMLParser? And how difficult is to add support for a new XML parsing library, for example, libexpat?

libxml2 is written in C, so it doesn't have exceptions.

Vanuan avatar Oct 04 '11 14:10 Vanuan

hm.. we stopped support xml2 (libXMLParser.cpp) because we couldn't throw any expetions from any callback. but you should be able to use it.

to support libexpat add you own parser class similar to XercesParser (or LibXMLParser) so it is about 15k bytes of code :)

2011/10/4 John Yani < [email protected]>

Thanks for advice!

I saw that there is XmlParser class from which XercesParser and LibXMLParser are inherited. Can I use LibXMLParser? And how difficult is to add support for a new XML parsing library, for example, libexpat?

libxml2 is written in C, so doesn't have exceptions.

Reply to this email directly or view it on GitHub: https://github.com/rafalrusin/xmlbeansxx/issues/4#issuecomment-2286702

stawel avatar Oct 04 '11 14:10 stawel