gdcmException.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004   Module:  $URL$
00005 
00006   Copyright (c) 2006-2010 Mathieu Malaterre
00007   All rights reserved.
00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 #ifndef GDCMEXCEPTION_H
00016 #define GDCMEXCEPTION_H
00017 
00018 #include <cassert>
00019 #include <cstdlib> // NULL
00020 #include <exception>
00021 #include <sstream> // ostringstream
00022 #include <stdexcept> // logic_error
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             // FIXME:  __PRETTY_FUNCTION__ is the non-mangled version for __GNUC__ compiler
00067             const char *func = "" /*__FUNCTION__*/)
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 } // end namespace gdcm
00091 
00092 #endif
00093 

Generated on Sat Dec 4 2010 08:58:42 for GDCM by doxygen 1.7.2
SourceForge.net Logo