CMS 3D CMS Logo

CSCDQM_Exception.h
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: CSCDQM_Exception.h
5  *
6  * Description: Custom Exception
7  *
8  * Version: 1.0
9  * Created: 11/14/2008 11:51:31 AM
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
14  * Company: CERN, CH
15  *
16  * =====================================================================================
17  */
18 
19 #ifndef CSCDQM_Exception_H
20 #define CSCDQM_Exception_H
21 
22 #include <string>
23 #include <exception>
24 
25 #include <xercesc/sax/ErrorHandler.hpp>
26 #include <xercesc/sax/SAXParseException.hpp>
27 
28 #include "CSCDQM_Logger.h"
29 
30 namespace cscdqm {
31 
37  class Exception : public std::exception {
38  private:
40 
41  public:
42  Exception(const std::string& message) throw() { this->message = message; }
43 
44  ~Exception() throw() override {}
45 
46  const char* what() const throw() override { return message.c_str(); }
47  };
48 
54  class XMLFileErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler {
55  public:
56  void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override {
57  char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
58  LOG_WARN << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
60  }
61 
62  void error(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override { this->fatalError(exc); }
63 
64  void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override {
65  char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
66  LOG_COUT << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
67  throw Exception(message);
68  }
69 
70  void resetErrors() override {}
71  };
72 
73 } // namespace cscdqm
74 
75 #endif
Application level Exception that is used to cut-off application execution in various cases...
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exc) override
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exc) override
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exc) override
const char * what() const override
Exception(const std::string &message)
#define LOG_WARN
Definition: CSCDQM_Logger.h:41
Takes care of errors and warnings while parsing XML files file in XML format.
#define LOG_COUT
Definition: CSCDQM_Logger.h:43