1 /*=========================================================================
4 Module: $RCSfile: gdcmException.h,v $
6 Date: $Date: 2004/06/20 18:08:47 $
7 Version: $Revision: 1.13 $
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 * Invalid file format exception
101 class GDCM_EXPORT gdcmFormatError : public gdcmException {
104 * Builds an file-related exception with minimal information: name of
105 * the thrower method and error message
107 * @param from name of the thrower
108 * @param error error description string
110 explicit gdcmFormatError(const std::string &from,
111 const std::string &error = "Invalid file format error")
112 throw() : gdcmException(from, error) {
116 //-----------------------------------------------------------------------------
117 /* prints exception stack on output stream
118 * @param os output stream
119 * @param e exception to print
120 * @returns output stream os
122 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
124 //-----------------------------------------------------------------------------
125 #endif // GDCM_EXCEPTION_H