# 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-2009 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 <string>
    00019 #include <stdexcept>
    00020 #include <sstream> // ostringstream
    00021
    00022 #include "gdcmTypes.h"
    00023
    00024 #include <assert.h> // FIXME
    00025
    00026
    00027 namespace gdcm
    00028 {
    00029
    00035 class Exception : public std::exception
    00036 {
    00037 public:
    00038   Exception(const char *desc = "None",
    00039             const char *file = __FILE__,
    00040             unsigned int lineNumber = __LINE__,
    00041             const char *loc = ""/*__FUNCTION__*/ )
    00042   {
    00043     Description = desc;
    00044     File = file;
    00045     Line = lineNumber;
    00046     Location = loc;
    00047   }
    00048
    00049   virtual ~Exception() throw() {}
    00050
    00052   Exception &operator= ( const Exception &orig )
    00053   {
    00054 //TODO
    00055 (void)orig;
    00056     return *this;
    00057   }
    00058
    00060   virtual bool operator==( const Exception &orig )
    00061   {
    00062 (void)orig;
    00063     return true;
    00064   }
    00065
    00067   const char* what() const throw()
    00068     {
    00069     static std::string strwhat;
    00070     std::ostringstream oswhat;
    00071     oswhat << File << ":" << Line << ":\n";
    00072     oswhat << Description;
    00073     strwhat = oswhat.str();
    00074     return strwhat.c_str();
    00075     }
    00076
    00078   const char * GetDescription() const { return Description.c_str(); }
    00079
    00080 private:
    00081   std::string  Description;
    00082   std::string  File;
    00083   unsigned int Line;
    00084   std::string  Location;
    00085 };
    00086
    00087 } // end namespace gdcm
    00088
    00089 #endif
    00090