throwable.h

Go to the documentation of this file.
00001 /* libthrowable - a C++ library to ease error handling and debugging
00002  *
00003  * Copyright (C) Matthias Langer 2006 <mlangc@gmx.at>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 #ifndef H_LIBTHROWABLE_THROWABLE
00021 #define H_LIBTHROWABLE_THROWABLE
00022 #include <stdexcept>
00023 #include <ostream>
00024 #include "util/util.h"
00025 #include "system.h"
00026 
00028 namespace libthrowable {
00029 
00036 class LIBTHROWABLE_API Throwable : public std::exception
00037 {
00038     public:
00042     virtual const char* what() const throw();
00043 
00045     virtual std::string what(unsigned indent) const throw();
00046 
00052     virtual std::string toString(int lineWidth = libthrowable::util::getTerminalWidth()) const throw();
00053 
00054     virtual ~Throwable() throw();
00055 
00056     protected:
00059     class DontManipulateStr {};
00060 
00062     Throwable(const std::string& msg, const DontManipulateStr& dummy) throw();
00063 
00067     std::string& getInternalString() throw(); 
00068 
00070     static std::string
00071     internalStrFromFilenameAndLinenumber(
00072         const std::string& className, const char *filename, int linenumber) throw();
00073 
00075     static std::string
00076     internalStrFromFilenameLinenumberAndFunction(
00077         const std::string& className, const char *filename, int linenumber, const char *function) throw();
00078     
00080     static std::string
00081     internalStrFromFilenameLinenumberAndMessage(
00082         const std::string& className, const char *filename, int linenumber, const std::string& message) throw();
00083 
00085     static std::string
00086     internalStrFromFilenameLinenumberFunctionAndMessage(
00087         const std::string& className, const char *filename, int linenumber, const char *function, const std::string& message) throw();
00088 
00090     static std::string
00091     internalStrFromCause(
00092         const std::string& className, const std::exception& cause) throw();
00093 
00096     static std::string
00097     internalStrFromCauseAndMessage(
00098         const std::string& className, const std::exception& cause, const std::string& message) throw(); 
00099 
00101     static std::string
00102     internalStrFromFilenameLinenumberAndCause(
00103         const std::string& className, const char *filename, int linenumber, const std::exception& cause) throw();
00104 
00106     static std::string
00107     internalStrFromFilenameLinenumberFunctionAndCause(
00108         const std::string& className, const char *filename, int linenumber, const char *function, const std::exception& cause) throw();
00109 
00112     static std::string
00113     internalStrFromFilenameLinenumberFunctionCauseAndMessage(
00114         const std::string& className, const char *filename, int linenumber, const char *function,
00115         const std::exception& cause, const std::string& msg) throw();
00116 
00118     static std::string 
00119     strFromFilenameAndLinenumber(
00120         const char *filename, int linenumber) throw();
00121 
00123     static std::string 
00124     strFromFilenameLinenumberAndFunction(
00125         const char *filename, int linenumber, const char *function) throw();
00126 
00128     static std::string 
00129     strFromFilenameLinenumberAndMessage(
00130         const char *filename, int linenumber, const std::string& msg) throw();
00131 
00133     static std::string
00134     strFromFilenameLinenumberFunctionAndMessage(
00135         const char *filename, int linenumber, const char *function, const std::string& msg) throw();
00136 
00138     static std::string strFromCause(const std::exception& cause) throw();
00139 
00142     static std::string strFromCauseAndMessage(const std::exception& cause, const std::string& msg) throw();
00143 
00145     static std::string
00146     strFromFilenameLinenumberAndCause(
00147         const char *filename, int linenumber, const std::exception& cause) throw();
00148 
00150     static std::string
00151     strFromFilenameLinenumberFunctionAndCause(
00152         const char *filename, int linenumber, const char *function, const std::exception& cause) throw();
00153 
00156     static std::string
00157     strFromFilenameLinenumberFunctionCauseAndMessage(
00158         const char *filename, int linenumber, const char *function, 
00159         const std::exception& cause, const std::string& msg) throw();   
00160 
00161     private:
00162     std::string _string;
00163 };
00164 
00167 LIBTHROWABLE_API std::ostream& operator<<(std::ostream& os, const Throwable& throwable);
00168 
00170 }//namespace
00171 #endif

Generated on Wed Jan 9 18:07:17 2008 for libthrowable by  doxygen 1.5.4  Hosted on  SourceForge.net Logo