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: 2007/08/22 16:14:04 $
00007   Version:   $Revision: 1.25 $
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_NAME_SPACE 
00029 {
00030 
00031 //-----------------------------------------------------------------------------
00035 class GDCM_EXPORT Exception : public std::exception
00036 {
00037 public:
00038    /*
00039     * \brief Builds an exception with minimal information: name of the thrower
00040     *        method and error message
00041     * @param from name of the thrower
00042     * @param error error description string
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 /* prints exception stack on output stream
00130  * @param os output stream
00131  * @param e exception to print
00132  * @returns output stream os
00133  */
00134 std::ostream& operator<<(std::ostream &os, const Exception &e);
00135 
00136 } // end namespace gdcm
00137 
00138 //-----------------------------------------------------------------------------
00139 #endif // GDCM_EXCEPTION_H

Generated on Fri Aug 24 12:59:30 2007 for gdcm by  doxygen 1.4.6