Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GDCMEXCEPTION_H
00016 #define GDCMEXCEPTION_H
00017
00018 #include <cassert>
00019 #include <cstdlib>
00020 #include <exception>
00021 #include <sstream>
00022 #include <stdexcept>
00023 #include <string>
00024
00025 namespace gdcm
00026 {
00027
00034 class Exception : public std::exception
00035 {
00040 typedef std::logic_error StringHolder;
00041
00043 static StringHolder CreateWhat(const char* const desc,
00044 const char* const file,
00045 const unsigned int lineNumber,
00046 const char* const func)
00047 {
00048 assert(desc != NULL);
00049 assert(file != NULL);
00050 assert(func != NULL);
00051 std::ostringstream oswhat;
00052 oswhat << file << ":" << lineNumber << " (" << func << "):\n";
00053 oswhat << desc;
00054 return StringHolder( oswhat.str() );
00055 }
00056
00057 public:
00063 explicit Exception(const char *desc = "None",
00064 const char *file = __FILE__,
00065 unsigned int lineNumber = __LINE__,
00066
00067 const char *func = "" )
00068 :
00069 What( CreateWhat(desc, file, lineNumber, func) ),
00070 Description(desc)
00071 {
00072 }
00073
00074 virtual ~Exception() throw() {}
00075
00077 const char* what() const throw()
00078 {
00079 return What.what();
00080 }
00081
00083 const char * GetDescription() const { return Description.what(); }
00084
00085 private:
00086 StringHolder What;
00087 StringHolder Description;
00088 };
00089
00090 }
00091
00092 #endif
00093