CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/CSCMonitorModule/interface/CSCDQM_Exception.h

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  CSCDQM_Exception.h
00005  *
00006  *    Description:  Custom Exception
00007  *
00008  *        Version:  1.0
00009  *        Created:  11/14/2008 11:51:31 AM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
00014  *        Company:  CERN, CH
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #ifndef CSCDQM_Exception_H
00020 #define CSCDQM_Exception_H
00021 
00022 #include <string>
00023 #include <exception>
00024 
00025 #include <xercesc/sax/ErrorHandler.hpp>
00026 #include <xercesc/sax/SAXParseException.hpp>
00027 
00028 #include "DQM/CSCMonitorModule/interface/CSCDQM_Logger.h"
00029 
00030 namespace cscdqm {
00031 
00037   class Exception: public std::exception {
00038     private:
00039 
00040       std::string message;
00041 
00042     public:
00043 
00044       Exception(const std::string& message) throw() {
00045         this->message = message;
00046       }
00047 
00048       virtual ~Exception() throw() { }
00049 
00050       virtual const char* what() const throw() {
00051         return message.c_str();
00052       }
00053 
00054   };
00055 
00061   class XMLFileErrorHandler : public XERCES_CPP_NAMESPACE::ErrorHandler {
00062 
00063     public:
00064 
00065       void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exc) {
00066         char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
00067         LOG_WARN << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
00068         XERCES_CPP_NAMESPACE::XMLString::release(&message);
00069       }
00070 
00071       void error(const XERCES_CPP_NAMESPACE::SAXParseException& exc) {
00072         this->fatalError(exc);
00073       }
00074 
00075       void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exc) {
00076         char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(exc.getMessage());
00077         LOG_COUT << "File: " << message << ". line: " << exc.getLineNumber() << " col: " << exc.getColumnNumber();
00078         throw Exception(message);
00079       }
00080 
00081       void resetErrors () { }
00082 
00083   };
00084 
00085 }
00086 
00087 #endif