You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jerald Dawson <jd...@mrk.com> on 2000/09/22 23:52:49 UTC

Help a newbie - Parse Exceptions

Hi All

I have a question that I'm hoping you can shed some light on. I downloaded
the sources and compiled with VC++ on win2K without incident. The test apps
run fine. 

I tried creating a simple app to test my understanding of how the stuff
works. I created an extremely simple handler class that basicly just takes
and prints out each element that it sees to cout. It prints the first
element and then throws a Debug Assertion Failed exception in dbgheap.c. I'm
sure its something I'm doing bone headed and the fact I'm a C++ newbie
doesn't help. 

The handler class I used is the example one from the Using the SAX api docs.
It inherits from HandlerBase and overrides the startElement and fatalError
methods. Any help would be appreciated.

Thanx

Jerald Dawson

The body of my app is:

// xmltest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "xmltest.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

////////////////////////////////////////////////////////////////////////////
/
// The one and only application object

CWinApp theApp;

//using namespace std;


int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        cerr << _T("Fatal Error: MFC initialization failed") << endl;
        nRetCode = 1;
    }
    else
    {
        // TODO: code your application's behavior here.
        try
        {
            XMLPlatformUtils::Initialize();
        }

        catch (const XMLException& toCatch)
        {
            cerr << "Error during initialization! Message:\n"
                << StrX(toCatch.getMessage()) << endl;
            return 1;
        }

        const char*                xmlFile = 0;
        SAXParser::ValSchemes    valScheme = SAXParser::Val_Never;
        bool                    doNamespaces = false;

        SAXParser parser; // lets create the parser

        parser.setValidationScheme(valScheme);
        parser.setDoNamespaces(doNamespaces);


        xmlFile = "D:\\xerces-c-src_1_2_0\\samples\\data\\personal.xml";
        try
        {
            MySAXHandler handler;
            parser.setDocumentHandler(&handler);
            parser.setErrorHandler(&handler);
            parser.parse(xmlFile);
        }

        catch (const XMLException& e)
        {
            cerr << "\nError during parsing: '" << xmlFile << "'\n"
                << "Exception message is:  \n"
                << StrX(e.getMessage()) << "\n" << endl;
            XMLPlatformUtils::Terminate();
            return 4;
        }

        catch (...)
        {
            cerr << "\nUnexpected exception during parsing: '" << xmlFile <<
"'\n";
            XMLPlatformUtils::Terminate();
            return 4;
        }


        XMLPlatformUtils::Terminate();
    }

    return nRetCode;
}


RE: Help a newbie - Parse Exceptions

Posted by Chris Howlett <ch...@webpearls.com>.

> -----Original Message-----
> From: Jerald Dawson [mailto:jdawson@mrk.com]
> Sent: September 22, 2000 5:53 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Help a newbie - Parse Exceptions
>
snip
>
> I tried creating a simple app to test my understanding of how the stuff
> works. I created an extremely simple handler class that basicly just takes
> and prints out each element that it sees to cout. It prints the first
> element and then throws a Debug Assertion Failed exception in
> dbgheap.c. I'm
> sure its something I'm doing bone headed and the fact I'm a C++ newbie
> doesn't help.
>

I don't know why this is happening, from the info you gave, but I have a
couple of comments that might help.

1. Your example should work if you created a Win32 console app with MFC and
used MySAXHandler.[cpp,hpp] sans change, as it appears you did, and provided
you didn't alter some code-generation-and-library-related default things in
your MSVC project settings and your stdafx.h.

2. The "classical" way to trigger a debug assertion in the MS heap manager,
much discussed on this list, is to free a string returned by transcode()
from an executable linked with a C++ run-time library which is incompatible
with the C++ run-time library linked with the xerces dll. Typically, that
just means you built the executable single-threaded (the distributed xerces
dll's were built multi-threaded). Having said that, it's pretty difficult to
link single-threaded after you've constructed an MFC console app. You'd
really have to work at it, hacking on your stdafx.h and your project
settings.
Also, unfortunately, your example doesn't look as if you'll be freeing
transcode returns except when an StrX gets deleted, which only happens in
your exception handlers, when temporary StrX's go out of scope. In that
case, you'd see one of your own exception messages, and you didn't mention
that. Hmmm - maybe you wouldn't see your exception message, now that I think
about it - I think MS deletes temporaries as early as possible and you might
lose the cerr buffer if an assertion fired in the StrX delete. I'm not sure
about that.

Bottom line - make sure your executable is building multi-threaded and maybe
set a breakpoint in your XMLException handler, to see if that's going off.

I hope this helps a bit.