1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2007/08/22 16:14:04 $
7 Version: $Revision: 1.25 $
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"
28 namespace GDCM_NAME_SPACE
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() { return Error;}
58 /// try to discover this (dynamic) class name
59 virtual std::string getName() const throw();
61 /// returns exception name string (overloads std::exception::what)
62 virtual const char *what() const throw() { return (const char *) *this;}
64 /// returns exception name string
65 operator const char *() const throw();
67 friend std::ostream &operator<<(std::ostream &os, const Exception &e);
70 /// error message part 1
72 /// error message part 2
77 //-----------------------------------------------------------------------------
79 * \brief File error exception thrown in the gdcm library
81 class GDCM_EXPORT FileError : public Exception
85 * \brief Builds an file-related exception with minimal information: name of
86 * the thrower method and error message
87 * @param from name of the thrower
88 * @param error error description string
90 explicit FileError(const std::string &from,
91 const std::string &error = "File error")
92 throw() : Exception(from, error) { }
96 //-----------------------------------------------------------------------------
98 * \brief Unexpected file format exception
100 class GDCM_EXPORT FormatUnexpected : public Exception
103 /// \brief Builds a file-related exception with minimal information:
104 /// name of the thrower method and error message
105 /// @param from name of the thrower
106 /// @param error error description string
107 explicit FormatUnexpected(const std::string &from,
108 const std::string &error = "Unexpected file format")
109 throw() : Exception( from, error ) { }
112 //-----------------------------------------------------------------------------
114 * \brief Invalid file format exception
116 class GDCM_EXPORT FormatError : public FormatUnexpected
119 /// \brief Builds a file-related exception with minimal information:
120 /// name of the thrower method and error message
121 /// @param from name of the thrower
122 /// @param error error description string
123 explicit FormatError(const std::string &from,
124 const std::string &error = "Invalid file format")
125 throw() : FormatUnexpected( from, error ) { }
128 //-----------------------------------------------------------------------------
129 /* prints exception stack on output stream
130 * @param os output stream
131 * @param e exception to print
132 * @returns output stream os
134 std::ostream& operator<<(std::ostream &os, const Exception &e);
136 } // end namespace gdcm
138 //-----------------------------------------------------------------------------
139 #endif // GDCM_EXCEPTION_H