[xsd-users] exception declaration

Boris Kolpackov boris at codesynthesis.com
Fri Oct 28 07:11:57 EDT 2005


Frederic,

frederic heem <frederic.heem at telsey.it> writes:

> At the moement, the following code is used to parse an xml file into c++
> object:
>   std::string fileConf("pippo.xml");
>   try {
>     m_pLidConf = (LidConf (fileConf));
>   } catch (...){
>     PTRACE(1,"HT MAN\tInitialiseLid configuration not valid");
>     return FALSE;
>   }
>
> The try catch statement catch any exceptions (catch (...)), is it possible
> to get in the generated header file the kind of exception thrown ? In java
> the throws keyword is compulsory in the function prototype but I don't
> think it is in C++.

I am not quite sure what you mean here. Do you want to catch specific
exceptions? If so they are defined in libxsd/xsd/cxx/tree/exceptions.hxx
(can be found in /usr/include/xsd/cxx/tree/exceptions.hxx if installed)
and also aliased (typedef'ed) in the generated header files (look for
'namespace xml_schema').

All exceptions thrown by C++/Tree mapping are derived from
xml_schema::exception so if you want to catch any exception thrown by
xsd-generated code, you can write something like this:


try
{
  m_pLidConf = (LidConf (fileConf));
}
catch (xml_schema::exception const& ex)
{
  PTRACE(1,
         "HT MAN\tInitialiseLid configuration not valid: %s",
         ex.what ());
}

hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20051028/ed83124e/attachment.pgp


More information about the xsd-users mailing list