0

Well, I just wrote a simple logger program with log4cxx lib, It is working fine so far, but then I realized the exception handling doesnt work as I expected:

#include <iostream>
#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/helpers/exception.h>

using namespace std;

using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::helpers;

int main(int argc, char *argv[])
{

  /* some code here ... */

  try
  {
     DOMConfigurator::configure("/path/to/logcfg.xml");
  }
  catch (Exception&)
  {
    cout << "error: problem in reading log config file" << endl;
    /* here I want to free up some objects! */
    exit(EXIT_FAILURE);
  }

}

So, now lets say the logcfg.xml does not exist, the program will print out this message and exit:

log4cxx: Could not open file [/wrong/path/to/logcfg.xml].

Which seems to me, it never reached my exception handler, but raised and handled in library itself. Could you please tell me what is proper way to handle such case ?

Thanks

atari83
  • 489
  • 1
  • 5
  • 15
  • 1
    The problem with log4cxx is the lack of proper documentation. – Anon Mail Dec 18 '15 at 14:18
  • 1
    It just [logs and ignores](https://android.googlesource.com/platform/external/apache-log4cxx/+/bf7b5ebcf7ce58764c86ab8c6f00ea1791d64026/src/main/cpp/domconfigurator.cpp#715) errors. Just bad implementation. – dewaffled Dec 18 '15 at 16:43
  • https://stackoverflow.com/questions/34356804/log4cxx-try-catch-wont-work-on-domconfiguratorconfigure – Thorsten Schöning Apr 15 '21 at 17:41

0 Answers0