Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmException.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmException.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/01/11 15:15:38 $
00007   Version:   $Revision: 1.21 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
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 
00029 {
00030 
00031 //-----------------------------------------------------------------------------
00035 class GDCM_EXPORT Exception : public std::exception
00036 {
00037 public:
00038    /*
00039     * Builds an exception with minimal information: name of the thrower
00040     * method and error message
00041     *
00042     * @param from name of the thrower
00043     * @param error error description string
00044     */
00045    explicit Exception(const std::string &from, const std::string &error = "")
00046       throw();
00047 
00051    virtual ~Exception() throw() {};
00052 
00054    static void fatal(const char *from) throw();
00055 
00057    const std::string &getError() const throw() {
00058       return Error;
00059    }
00060 
00062    virtual std::string getName() const throw();
00063 
00065    virtual const char *what() const throw() {
00066       return (const char *) *this;
00067    }
00068 
00070    operator const char *() const throw();
00071 
00072    friend std::ostream &operator<<(std::ostream &os, const Exception &e);
00073 
00074 protected:
00076    std::string From;
00078    std::string Error;
00079 };
00080 
00081 
00082 //-----------------------------------------------------------------------------
00086 class GDCM_EXPORT FileError : public Exception
00087 {
00088 public:
00095    explicit FileError(const std::string &from,
00096                           const std::string &error = "File error")
00097       throw() : Exception(from, error) { }
00098 };
00099 
00100 
00101 //-----------------------------------------------------------------------------
00105 class GDCM_EXPORT FormatUnexpected : public Exception
00106 {
00107 public:
00112    explicit FormatUnexpected(const std::string &from,
00113                              const std::string &error = "Unexpected file format")
00114       throw() : Exception( from, error ) { }
00115 };
00116 
00117 //-----------------------------------------------------------------------------
00121 class GDCM_EXPORT FormatError : public FormatUnexpected
00122 {
00123 public:
00128    explicit FormatError(const std::string &from,
00129                         const std::string &error = "Invalid file format")
00130       throw() : FormatUnexpected( from, error ) { }
00131 };
00132 
00133 //-----------------------------------------------------------------------------
00134 /* prints exception stack on output stream
00135  * @param os output stream
00136  * @param e exception to print
00137  * @returns output stream os
00138  */
00139 std::ostream& operator<<(std::ostream &os, const Exception &e);
00140 
00141 } // end namespace gdcm
00142 
00143 //-----------------------------------------------------------------------------
00144 #endif // GDCM_EXCEPTION_H

Generated on Thu Feb 10 22:17:58 2005 for gdcm by doxygen 1.3.6