1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2004/10/12 04:35:46 $
7 Version: $Revision: 1.17 $
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"
29 //-----------------------------------------------------------------------------
31 * Any exception thrown in the gdcm library
33 class GDCM_EXPORT Exception : public std::exception
37 * Builds an exception with minimal information: name of the thrower
38 * method and error message
40 * @param from name of the thrower
41 * @param error error description string
43 explicit Exception(const std::string &from, const std::string &error = "")
47 * \brief virtual destructor makes this class dynamic
49 virtual ~Exception() throw() {};
51 /// exception caught within exception class: print error message and die
52 static void fatal(const char *from) throw();
54 /// returns error message
55 const std::string &getError() const throw() {
59 /// try to discover this (dynamic) class name
60 virtual std::string getName() const throw();
62 /// returns exception name string (overloads std::exception::what)
63 virtual const char *what() const throw() {
64 return (const char *) *this;
67 /// returns exception name string
68 operator const char *() const throw();
70 friend std::ostream& operator<<(std::ostream &os, const Exception &e);
73 /// error message part 1
75 /// error message part 2
80 //-----------------------------------------------------------------------------
82 * File error exception thrown in the gdcm library
84 class GDCM_EXPORT FileError : public Exception
88 * \brief Builds an file-related exception with minimal information: name of
89 * the thrower method and error message
90 * @param from name of the thrower
91 * @param error error description string
93 explicit FileError(const std::string &from,
94 const std::string &error = "File error")
95 throw() : Exception(from, error) { }
99 //-----------------------------------------------------------------------------
101 * \brief Unexpected file format exception
103 class GDCM_EXPORT FormatUnexpected : public Exception
106 /// \brief Builds a file-related exception with minimal information:
107 /// name of the thrower method and error message
108 /// @param from name of the thrower
109 /// @param error error description string
110 explicit FormatUnexpected(const std::string &from,
111 const std::string &error = "Unexpected file format")
112 throw() : Exception( from, error ) { }
115 //-----------------------------------------------------------------------------
117 * \brief Invalid file format exception
119 class GDCM_EXPORT FormatError : public FormatUnexpected
122 /// \brief Builds a file-related exception with minimal information:
123 /// name of the thrower method and error message
124 /// @param from name of the thrower
125 /// @param error error description string
126 explicit FormatError(const std::string &from,
127 const std::string &error = "Invalid file format")
128 throw() : FormatUnexpected( from, error ) { }
131 //-----------------------------------------------------------------------------
132 /* prints exception stack on output stream
133 * @param os output stream
134 * @param e exception to print
135 * @returns output stream os
137 std::ostream& operator<<(std::ostream &os, const Exception &e);
139 } // end namespace gdcm
141 //-----------------------------------------------------------------------------
142 #endif // GDCM_EXCEPTION_H