00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef _GDCM_EXCEPTION_H_
00020 #define _GDCM_EXCEPTION_H_
00021 
00022 #include "gdcmCommon.h"
00023 
00024 #include <string>
00025 #include <iostream>
00026 #include <exception>
00027 
00028 namespace GDCM_NAME_SPACE 
00029 {
00030 
00031 
00035 class GDCM_EXPORT Exception : public std::exception
00036 {
00037 public:
00038    
00039 
00040 
00041 
00042 
00043 
00044    explicit Exception(const std::string &from, const std::string &error = "")
00045       throw();
00046 
00050    virtual ~Exception() throw() {}
00051 
00053    static void fatal(const char *from) throw();
00054 
00056    const std::string &getError() const throw() { return Error;}
00057 
00059    virtual std::string getName() const throw();
00060 
00062    virtual const char *what() const throw() { return (const char *) *this;}
00063 
00065    operator const char *() const throw();
00066 
00067    friend std::ostream &operator<<(std::ostream &os, const Exception &e);
00068 
00069 protected:
00071    std::string From;
00073    std::string Error;
00074 };
00075 
00076 
00077 
00081 class GDCM_EXPORT FileError : public Exception
00082 {
00083 public:
00090    explicit FileError(const std::string &from,
00091                           const std::string &error = "File error")
00092       throw() : Exception(from, error) { }
00093 };
00094 
00095 
00096 
00100 class GDCM_EXPORT FormatUnexpected : public Exception
00101 {
00102 public:
00107    explicit FormatUnexpected(const std::string &from,
00108                              const std::string &error = "Unexpected file format")
00109       throw() : Exception( from, error ) { }
00110 };
00111 
00112 
00116 class GDCM_EXPORT FormatError : public FormatUnexpected
00117 {
00118 public:
00123    explicit FormatError(const std::string &from,
00124                         const std::string &error = "Invalid file format")
00125       throw() : FormatUnexpected( from, error ) { }
00126 };
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 std::ostream& operator<<(std::ostream &os, const Exception &e);
00135 
00136 } 
00137 
00138 
00139 #endif // GDCM_EXCEPTION_H