CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Utilities/src/Exception.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 namespace cms {
00005 
00006   Exception::Exception(std::string const& aCategory) :
00007     std::exception(),
00008     ost_(),
00009     category_(1, aCategory),
00010     what_()
00011   {
00012   }
00013 
00014   Exception::Exception(std::string const& aCategory,
00015                        std::string const& message) :
00016     std::exception(),
00017     ost_(),
00018     category_(1, aCategory),
00019     what_()
00020   {
00021     ost_ << message;
00022     if(!message.empty()) {
00023         unsigned sz = message.size()-1;
00024         if(message[sz]!='\n' && message[sz]!=' ') ost_ << " ";
00025     }
00026   }
00027 
00028   Exception::Exception(std::string const& aCategory,
00029                        std::string const& message,
00030                        Exception const& another) :
00031     std::exception(),
00032     ost_(),
00033     category_(1, aCategory),
00034     what_()
00035   {
00036     ost_ << message;
00037     // check for newline at end of message first
00038     if(!message.empty() && message[message.size()-1]!='\n')
00039       ost_ << "\n";
00040     category_.push_back(another.category());
00041     append(another);
00042   }
00043 
00044   Exception::Exception(Exception const& other):
00045     std::exception(),
00046     ost_(),
00047     category_(other.category_),
00048     what_(other.what_)
00049   {
00050     ost_ << other.ost_.str();
00051   }
00052 
00053   Exception::~Exception() throw() {
00054   }
00055   
00056   std::string Exception::explainSelf() const {
00057     std::ostringstream ost;
00058     std::string part(ost_.str());
00059     // Remove any trailing newline
00060 
00061     ost << "---- " << category() << " BEGIN\n"
00062         << part;
00063 
00064     if(!part.empty() && part[part.size()-1]!='\n') ost << "\n";
00065     ost << "---- " << category() << " END\n";
00066 
00067     return ost.str();
00068   }
00069 
00070   Exception::CategoryList const& Exception::history() const {
00071     return category_;
00072   }
00073 
00074   std::string Exception::category() const {
00075     return category_.front();
00076   }
00077   
00078   std::string Exception::rootCause() const {
00079     return category_.back();
00080   }
00081   
00082   void Exception::append(Exception const& another) {
00083     ost_ << another.explainSelf();
00084   }
00085 
00086   void Exception::append(std::string const& more_information) {
00087     ost_ << more_information;
00088   }
00089 
00090   void Exception::append(char const* more_information) {
00091     ost_ << more_information;
00092   }
00093   
00094   // --------------------------------
00095   // required for being a std::exception
00096 
00097   char const* Exception::what() const throw() {
00098     what_ = explainSelf();
00099     return what_.c_str();
00100   }
00101 
00102   std::exception* Exception::clone() const {
00103     return new Exception(*this);
00104   }
00105 
00106   void Exception::rethrow() {
00107     throw *this;
00108   }
00109   
00110 
00111 
00112 }