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

Generated on Tue Mar 27 2012 18:19:32 for GDCM by doxygen 1.8.0
SourceForge.net Logo