Liquid XML Data Binder (C++, Java, VB6) / Reference / C++ / Key Concepts / Exceptions
In This Topic
    Exceptions
    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.

    Example

    Schema Fragment

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


    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="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ElmSequence.xsd">
        <ElmChoiceComplexType>
            <StringElm>ElmChoiceComplexTypestringElmValue</StringElm>
        </ElmChoiceComplexType>
        <BasicElement>
            <StringElm>BasicElementstringElmValue</StringElm>
        </BasicElement>
        <stringElm>stringElmValue</stringElm>
    </ElmSequence>

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

    Code

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

        spElm->FromXmlFile(_T("Invalid_ElmSequence_BadOrder.xml"));
    }
    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.

    Output

    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.