1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2004/08/16 04:25:18 $
7 Version: $Revision: 1.15 $
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.htm 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"
27 //-----------------------------------------------------------------------------
29 * Any exception thrown in the gdcm library
31 class GDCM_EXPORT gdcmException : public std::exception
35 * Builds an exception with minimal information: name of the thrower
36 * method and error message
38 * @param from name of the thrower
39 * @param error error description string
41 explicit gdcmException(const std::string &from, const std::string &error = "")
45 * \brief virtual destructor makes this class dynamic
47 virtual ~gdcmException() throw() {};
49 /// exception caught within exception class: print error message and die
50 static void fatal(const char *from) throw();
52 /// returns error message
53 const std::string &getError() const throw() {
57 /// try to discover this (dynamic) class name
58 virtual std::string getName() const throw();
60 /// returns exception name string (overloads std::exception::what)
61 virtual const char *what() const throw() {
62 return (const char *) *this;
65 /// returns exception name string
66 operator const char *() const throw();
68 friend std::ostream& operator<<(std::ostream &os, const gdcmException &e);
71 /// error message part 1
73 /// error message part 2
78 //-----------------------------------------------------------------------------
80 * File error exception thrown in the gdcm library
82 class GDCM_EXPORT gdcmFileError : public gdcmException
86 * \brief Builds an file-related exception with minimal information: name of
87 * the thrower method and error message
88 * @param from name of the thrower
89 * @param error error description string
91 explicit gdcmFileError(const std::string &from,
92 const std::string &error = "File error")
93 throw() : gdcmException(from, error) { }
97 //-----------------------------------------------------------------------------
99 * \brief Unexpected file format exception
101 class GDCM_EXPORT gdcmFormatUnexpected : public gdcmException
104 /// \brief Builds a file-related exception with minimal information:
105 /// name of the thrower method and error message
106 /// @param from name of the thrower
107 /// @param error error description string
108 explicit gdcmFormatUnexpected(const std::string &from,
109 const std::string &error = "Unexpected file format")
110 throw() : gdcmException( from, error ) { }
113 //-----------------------------------------------------------------------------
115 * \brief Invalid file format exception
117 class GDCM_EXPORT gdcmFormatError : public gdcmFormatUnexpected
120 /// \brief Builds a file-related exception with minimal information:
121 /// name of the thrower method and error message
122 /// @param from name of the thrower
123 /// @param error error description string
124 explicit gdcmFormatError(const std::string &from,
125 const std::string &error = "Invalid file format")
126 throw() : gdcmFormatUnexpected( from, error ) { }
129 //-----------------------------------------------------------------------------
130 /* prints exception stack on output stream
131 * @param os output stream
132 * @param e exception to print
133 * @returns output stream os
135 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
137 //-----------------------------------------------------------------------------
138 #endif // GDCM_EXCEPTION_H