1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2004/08/02 14:06:58 $
7 Version: $Revision: 1.14 $
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 {
34 * Builds an exception with minimal information: name of the thrower
35 * method and error message
37 * @param from name of the thrower
38 * @param error error description string
40 explicit gdcmException(const std::string &from, const std::string &error = "")
44 * \brief virtual destructor makes this class dynamic
46 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(void) 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 {
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 gdcmFileError(const std::string &from,
91 const std::string &error = "File error")
92 throw() : gdcmException(from, error) {
97 //-----------------------------------------------------------------------------
99 * \brief Unexpected file format exception
101 class GDCM_EXPORT gdcmFormatUnexpected : public gdcmException {
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 gdcmFormatUnexpected(const std::string &from,
108 const std::string &error = "Unexpected file format")
109 throw() : gdcmException( from, error ) { }
112 //-----------------------------------------------------------------------------
114 * \brief Invalid file format exception
116 class GDCM_EXPORT gdcmFormatError : public gdcmFormatUnexpected {
118 /// \brief Builds a file-related exception with minimal information:
119 /// name of the thrower method and error message
120 /// @param from name of the thrower
121 /// @param error error description string
122 explicit gdcmFormatError(const std::string &from,
123 const std::string &error = "Invalid file format")
124 throw() : gdcmFormatUnexpected( from, error ) { }
127 //-----------------------------------------------------------------------------
128 /* prints exception stack on output stream
129 * @param os output stream
130 * @param e exception to print
131 * @returns output stream os
133 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
135 //-----------------------------------------------------------------------------
136 #endif // GDCM_EXCEPTION_H