[xsd-users] Document parsing failed
boris at codesynthesis.com
Fri Jul 13 09:52:06 EDT 2007
Ray Lischner <rlischner at proteus-technologies.com> writes:
> Why can't what() return the full information, as is the convention?
For several reasons. First, what() is "hard coded" to return char*
while XSD exceptions can use char or wchar_t depending on the
character type selected during schema compilation. Also, since
what() returns "const char*", the string buffer that holds the
text has to be allocated in the exception itself. Because what()
is no-throw, it can be tricky to populate that buffer within
what() itself so the text has to be pre-formatted when exception
is created which can be quite wasteful.
Then there are conceptual reasons. Many people believe that
what() should return a string that is always the same for
this type of exception so that it is more like a key which
can be used to look-up other information (e.g., a language-
specific error description, etc.). The fact that it returns
const char* and not std::string as well as the no-throw
exception specification all suggest this semantics.
We could have provided another function in our exception
hierarchy that returns the description as a string. We
decided against that method since most of the time the
next operation on that string will be to print it and the
whole string creating would be a waste. Instead we decided
to provide a way to print the exception directly to std::ostream.
Note also that you can always catch a concrete exception (e.g.,
xml_schema::parsing) which includes all the information you
see when you print the exception but in a structured way that
is more convenient for programmatic access.
More information about the xsd-users