1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2005/02/11 16:36:52 $
7 Version: $Revision: 1.22 $
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 * \brief Builds an exception with minimal information: name of the thrower
40 * method and error message
41 * @param from name of the thrower
42 * @param error error description string
44 explicit Exception(const std::string &from, const std::string &error = "")
48 * \brief virtual destructor makes this class dynamic
50 virtual ~Exception() throw() {};
52 /// exception caught within exception class: print error message and die
53 static void fatal(const char *from) throw();
55 /// returns error message
56 const std::string &getError() const throw() {
60 /// try to discover this (dynamic) class name
61 virtual std::string getName() const throw();
63 /// returns exception name string (overloads std::exception::what)
64 virtual const char *what() const throw() {
65 return (const char *) *this;
68 /// returns exception name string
69 operator const char *() const throw();
71 friend std::ostream &operator<<(std::ostream &os, const Exception &e);
74 /// error message part 1
76 /// error message part 2
81 //-----------------------------------------------------------------------------
83 * \brief File error exception thrown in the gdcm library
85 class GDCM_EXPORT FileError : public Exception
89 * \brief Builds an file-related exception with minimal information: name of
90 * the thrower method and error message
91 * @param from name of the thrower
92 * @param error error description string
94 explicit FileError(const std::string &from,
95 const std::string &error = "File error")
96 throw() : Exception(from, error) { }
100 //-----------------------------------------------------------------------------
102 * \brief Unexpected file format exception
104 class GDCM_EXPORT FormatUnexpected : public Exception
107 /// \brief Builds a file-related exception with minimal information:
108 /// name of the thrower method and error message
109 /// @param from name of the thrower
110 /// @param error error description string
111 explicit FormatUnexpected(const std::string &from,
112 const std::string &error = "Unexpected file format")
113 throw() : Exception( from, error ) { }
116 //-----------------------------------------------------------------------------
118 * \brief Invalid file format exception
120 class GDCM_EXPORT FormatError : public FormatUnexpected
123 /// \brief Builds a file-related exception with minimal information:
124 /// name of the thrower method and error message
125 /// @param from name of the thrower
126 /// @param error error description string
127 explicit FormatError(const std::string &from,
128 const std::string &error = "Invalid file format")
129 throw() : FormatUnexpected( from, error ) { }
132 //-----------------------------------------------------------------------------
133 /* prints exception stack on output stream
134 * @param os output stream
135 * @param e exception to print
136 * @returns output stream os
138 std::ostream& operator<<(std::ostream &os, const Exception &e);
140 } // end namespace gdcm
142 //-----------------------------------------------------------------------------
143 #endif // GDCM_EXCEPTION_H