Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:53:59

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  CSCDQM_Exception.h
0005  *
0006  *    Description:  Custom Exception
0007  *
0008  *        Version:  1.0
0009  *        Created:  11/14/2008 11:51:31 AM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #ifndef CSCDQM_Exception_H
0020 #define CSCDQM_Exception_H
0021 
0022 #include <string>
0023 #include <exception>
0024 
0025 #include <xercesc/sax/ErrorHandler.hpp>
0026 #include <xercesc/sax/SAXParseException.hpp>
0027 
0028 #include "CSCDQM_Logger.h"
0029 
0030 namespace cscdqm {
0031 
0032   /**
0033    * @class Exception
0034    * @brief Application level Exception that is used to cut-off application
0035    * execution in various cases.
0036    */
0037   class Exception : public std::exception {
0038   private:
0039     std::string message;
0040 
0041   public:
0042     Exception(const std::string& message) throw() { this->message = message; }
0043 
0044     ~Exception() throw() override {}
0045 
0046     const char* what() const throw() override { return message.c_str(); }
0047   };
0048 
0049   /**
0050    * @class XMLFileErrorHandler
0051    * @brief Takes care of errors and warnings while parsing XML files
0052    * file in XML format.
0053    */
0054   class XMLFileErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler {
0055   public:
0056     void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override {
0057       char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
0058       LOG_WARN << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
0059       XERCES_CPP_NAMESPACE::XMLString::release(&message);
0060     }
0061 
0062     void error(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override { this->fatalError(exc); }
0063 
0064     void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exc) override {
0065       char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
0066       LOG_COUT << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
0067       throw Exception(message);
0068     }
0069 
0070     void resetErrors() override {}
0071   };
0072 
0073 }  // namespace cscdqm
0074 
0075 #endif