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