MBSim

Project Page
mbsim_event.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: thschindler@users.berlios.de
00018  */
00019 
00020 #ifndef _MBSIM_EVENT_H_
00021 #define _MBSIM_EVENT_H_
00022 
00023 #include <string>
00024 #include <exception>
00025 #include <xercesc/dom/DOMElement.hpp>
00026 #include <mbxmlutilshelper/dom.h>
00027 
00028 namespace MBSim {
00029 
00030   class Element;
00031 
00038   class MBSimError : public std::exception {
00039     public:
00045       MBSimError(const Element *context, const std::string &mbsim_error_message_) throw(); 
00046 
00051       MBSimError(const std::string &mbsim_error_message_) throw(); 
00052       
00053       virtual ~MBSimError() throw() {}
00054 
00055       /* \brief set the context of the error
00056        * Use this function to set the context in a catch(...) block if the context is not known
00057        * at the original throw statement. */
00058       void setContext(const Element *context);
00059 
00060       const std::string& getErrorMessage() const { return mbsim_error_message; }
00061 
00062       const std::string& getPath() const { return path; }
00063 
00064       const std::vector<MBXMLUtils::EmbedDOMLocator>& getLocationStack() const { return locationStack; }
00065 
00066       virtual const char* what() const throw();
00067 
00068     private:
00072       std::string mbsim_error_message;
00073 
00074       std::string path;
00075 
00076       std::vector<MBXMLUtils::EmbedDOMLocator> locationStack;
00077 
00078       // just a string to store the memory which is returned by the what() function
00079       mutable std::string whatMsg;
00080   };
00081 
00082   // Helper to throw a error with this as the context of the error
00083   #define THROW_MBSIMERROR(msg) \
00084     throw MBSim::MBSimError(this, msg)
00085 }
00086 
00087 #endif /* _MBSIM_EVENT_H */
00088