1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2005/01/11 15:15:38 $
7 Version: $Revision: 1.21 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #ifndef GDCM_EXCEPTION_H
20 #define GDCM_EXCEPTION_H
22 #include "gdcmCommon.h"
31 //-----------------------------------------------------------------------------
33 * \brief Any exception thrown in the gdcm library
35 class GDCM_EXPORT Exception : public std::exception
39 * Builds an exception with minimal information: name of the thrower
40 * method and error message
42 * @param from name of the thrower
43 * @param error error description string
45 explicit Exception(const std::string &from, const std::string &error = "")
49 * \brief virtual destructor makes this class dynamic
51 virtual ~Exception() throw() {};
53 /// exception caught within exception class: print error message and die
54 static void fatal(const char *from) throw();
56 /// returns error message
57 const std::string &getError() const throw() {
61 /// try to discover this (dynamic) class name
62 virtual std::string getName() const throw();
64 /// returns exception name string (overloads std::exception::what)
65 virtual const char *what() const throw() {
66 return (const char *) *this;
69 /// returns exception name string
70 operator const char *() const throw();
72 friend std::ostream &operator<<(std::ostream &os, const Exception &e);
75 /// error message part 1
77 /// error message part 2
82 //-----------------------------------------------------------------------------
84 * \brief File error exception thrown in the gdcm library
86 class GDCM_EXPORT FileError : public Exception
90 * \brief Builds an file-related exception with minimal information: name of
91 * the thrower method and error message
92 * @param from name of the thrower
93 * @param error error description string
95 explicit FileError(const std::string &from,
96 const std::string &error = "File error")
97 throw() : Exception(from, error) { }
101 //-----------------------------------------------------------------------------
103 * \brief Unexpected file format exception
105 class GDCM_EXPORT FormatUnexpected : public Exception
108 /// \brief Builds a file-related exception with minimal information:
109 /// name of the thrower method and error message
110 /// @param from name of the thrower
111 /// @param error error description string
112 explicit FormatUnexpected(const std::string &from,
113 const std::string &error = "Unexpected file format")
114 throw() : Exception( from, error ) { }
117 //-----------------------------------------------------------------------------
119 * \brief Invalid file format exception
121 class GDCM_EXPORT FormatError : public FormatUnexpected
124 /// \brief Builds a file-related exception with minimal information:
125 /// name of the thrower method and error message
126 /// @param from name of the thrower
127 /// @param error error description string
128 explicit FormatError(const std::string &from,
129 const std::string &error = "Invalid file format")
130 throw() : FormatUnexpected( from, error ) { }
133 //-----------------------------------------------------------------------------
134 /* prints exception stack on output stream
135 * @param os output stream
136 * @param e exception to print
137 * @returns output stream os
139 std::ostream& operator<<(std::ostream &os, const Exception &e);
141 } // end namespace gdcm
143 //-----------------------------------------------------------------------------
144 #endif // GDCM_EXCEPTION_H