Liquid XML Data Binder (C++, Java, VB6) / Reference / C++ / Key Concepts / Exceptions
In This Topic
    In This Topic

    The generated wrapper classes throw a number of exceptions, all of which are derived from LtXmlLib20::CLtException. The CLtException exception class is capable of holding an inner exception describing the detail of where the error occurred, to get the most from an exception it is best to view the whole chain of exceptions (the method CLtException.GetFullMessage() gets the error messages from all the nested exceptions for you).

    A key point to note when catching exceptions is that all CLtException derived exceptions are thrown by value and caught by reference.


    Schema Fragment

    <xs:element name="ElmSequence">
                <xs:element ref="BasicElement"/>
                <xs:element name="ElmChoiceComplexType" type="BasicComplexType"/>
                <xs:element name="stringElm" type="xs:string"/>

    Note the first element in ElmSequence must be BasicElement

    Sample File Invalid_ElmSequence_BadOrder.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <ElmSequence xmlns:xsi="" xsi:noNamespaceSchemaLocation="ElmSequence.xsd">

    Note the first child element of ElmSequence is NOT BasicElement, but ElmChoiceComplexType, making the XML document invalid.


        ElmSequence::CElmSequencePtr spElm = ElmSequence::CElmSequence::CreateInstance();

    catch (CLtException& e)
        _tprintf(_T("Error - %s\n"), e.GetFullMessage().c_str());

    Because the XML file is invalid an error is raised when we attempt to load it. Note the exception is caught by reference.


    Error - Failed to process the child elements in element [ElmSequence]
    Failed to find a required element [BasicElement]

    The first line is the error text from the exception we caught, the second line is the error text from the inner exception.
    It is also possible for the innerexception to have an inner exception etc.