Main Page | File List | Related Pages

gdcmException.h

00001 // gdcmException.h
00002 //-----------------------------------------------------------------------------
00003 #ifndef GDCM_EXCEPTION_H
00004 #define GDCM_EXCEPTION_H
00005 
00006 #include "gdcmCommon.h"
00007 #include <string>
00008 #include <iostream>
00009 #include <exception>
00010 
00011 //-----------------------------------------------------------------------------
00012 /*
00013  * Any exception thrown in the gdcm library
00014  */
00015 class GDCM_EXPORT gdcmException : public std::exception {
00016 public:
00017    /*
00018     * Builds an exception with minimal information: name of the thrower
00019     * method and error message
00020     *
00021     * @param from name of the thrower
00022     * @param error error description string
00023     */
00024    explicit gdcmException(const std::string &from, const std::string &error = "")
00025     throw();
00026 
00027    /*
00028     * virtual destructor makes this class dynamic
00029     */
00030    virtual ~gdcmException() throw() {
00031    }
00032 
00033    // exception caught within exception class: print error message and die
00034    static void fatal(const char *from) throw();
00035 
00036    // returns error message
00037    const std::string &getError(void) const throw() {
00038     return error;
00039    }
00040 
00041    // try to discover this (dynamic) class name
00042    virtual std::string getName() const throw();
00043 
00044    // returns exception name string (overloads std::exception::what)
00045    virtual const char *what() const throw() {
00046     return (const char *) *this;
00047    }
00048 
00049    // returns exception name string
00050    operator const char *() const throw();
00051 
00052    friend std::ostream& operator<<(std::ostream &os, const gdcmException &e);
00053 
00054 protected:
00055    // error message
00056    std::string from;
00057    // error message
00058    std::string error;
00059 };
00060 
00061 
00062 //-----------------------------------------------------------------------------
00063 /*
00064  * File error exception thrown in the gdcm library
00065  */
00066 class GDCM_EXPORT gdcmFileError : public gdcmException {
00067 public:
00068    /*
00069     * Builds an file-related exception with minimal information: name of
00070     * the thrower method and error message
00071     *
00072     * @param from name of the thrower
00073     * @param error error description string
00074     */
00075    explicit gdcmFileError(const std::string &from,
00076                           const std::string &error = "File error")
00077       throw() : gdcmException(from, error) {
00078    }
00079 };
00080 
00081 
00082 //-----------------------------------------------------------------------------
00083 /*
00084  * Invalid file format exception
00085  */
00086 class GDCM_EXPORT gdcmFormatError : public gdcmException {
00087 public:
00088    /*
00089     * Builds an file-related exception with minimal information: name of
00090     * the thrower method and error message
00091     *
00092     * @param from name of the thrower
00093     * @param error error description string
00094     */
00095    explicit gdcmFormatError(const std::string &from,
00096                             const std::string &error = "Invalid file format error")
00097       throw() : gdcmException(from, error) {
00098    }
00099 };
00100 
00101 //-----------------------------------------------------------------------------
00102 /* prints exception stack on output stream
00103  * @param os output stream
00104  * @param e exception to print
00105  * @returns output stream os
00106  */
00107 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
00108 
00109 //-----------------------------------------------------------------------------
00110 #endif // GDCM_EXCEPTION_H

Generated on Mon Feb 14 16:13:43 2005 for gdcm by doxygen 1.3.6