Re: handling exception without stderr printings



Thank you very much for your answer. I test it and it works like i want. However i have been working before directly with libxml2 and using that kind of calling back functions to handle errors. I passed to use libxml++ because those things were resolved and i dont have to manage static functions directly. I hope that in future changes to libxml++ this things can be considered. (for example like parser.set_throw_messages(true);)


2013/7/31 Kjell Ahlstedt <kjell ahlstedt bredband net>
The printing to stderr is done by libxml2, not by libxml++. It was not as easy as I thought to find out how to avoid it, and the solution I found is somewhat bizarre.
The libxml2 function initGenericErrorDefaultFunc() takes a pointer to a function pointer.

#include <libxml++/libxml++.h>
#include <libxml/xmlerror.h>

#include <iostream>
#include <stdlib.h>

using namespace std;
using namespace xmlpp;

static void myGenericErrorFunc(void* /* parsing context */,
  const char* /* format (like fprintf) */, ...)
{
  // Don't print anything.
  // libxml2's default GenericErrorFunc prints to stderr.
}

static xmlGenericErrorFunc pGenericErrorFunc = myGenericErrorFunc;

int main()
{
initGenericErrorDefaultFunc(&pGenericErrorFunc);


try
{
xmlpp::DomParser parser;
parser.set_throw_messages(true);
parser.parse_file("config.xml");
}
catch (const xmlpp::exception& ex)
{
cout << ex.what() << endl;
}

return 0;
}

2013-07-30 23:12, Pablo Madoery skrev:


The problem i have is the following:
In the case that "config.xml" doesn't exist I want that only exception cout be printed (and not stderr).
But that's not the case. The exception is raised and the stderr is printed too.
How can i make that stderr dont be printed.
Can you help me?.
Thank you very much.






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]