2 //-----------------------------------------------------------------------------
3 #ifndef GDCM_EXCEPTION_H
4 #define GDCM_EXCEPTION_H
6 #include "gdcmCommon.h"
11 //-----------------------------------------------------------------------------
13 * Any exception thrown in the gdcm library
15 class GDCM_EXPORT gdcmException : public std::exception {
18 * Builds an exception with minimal information: name of the thrower
19 * method and error message
21 * @param from name of the thrower
22 * @param error error description string
24 explicit gdcmException(const std::string &from, const std::string &error = "")
28 * \brief virtual destructor makes this class dynamic
30 virtual ~gdcmException() throw() {
33 /// exception caught within exception class: print error message and die
34 static void fatal(const char *from) throw();
36 /// returns error message
37 const std::string &getError(void) const throw() {
41 /// try to discover this (dynamic) class name
42 virtual std::string getName() const throw();
44 /// returns exception name string (overloads std::exception::what)
45 virtual const char *what() const throw() {
46 return (const char *) *this;
49 /// returns exception name string
50 operator const char *() const throw();
52 friend std::ostream& operator<<(std::ostream &os, const gdcmException &e);
55 /// error message part 1
57 /// error message part 2
62 //-----------------------------------------------------------------------------
64 * File error exception thrown in the gdcm library
66 class GDCM_EXPORT gdcmFileError : public gdcmException {
69 * \brief Builds an file-related exception with minimal information: name of
70 * the thrower method and error message
71 * @param from name of the thrower
72 * @param error error description string
74 explicit gdcmFileError(const std::string &from,
75 const std::string &error = "File error")
76 throw() : gdcmException(from, error) {
81 //-----------------------------------------------------------------------------
83 * Invalid file format exception
85 class GDCM_EXPORT gdcmFormatError : public gdcmException {
88 * Builds an file-related exception with minimal information: name of
89 * the thrower method and error message
91 * @param from name of the thrower
92 * @param error error description string
94 explicit gdcmFormatError(const std::string &from,
95 const std::string &error = "Invalid file format error")
96 throw() : gdcmException(from, error) {
100 //-----------------------------------------------------------------------------
101 /* prints exception stack on output stream
102 * @param os output stream
103 * @param e exception to print
104 * @returns output stream os
106 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
108 //-----------------------------------------------------------------------------
109 #endif // GDCM_EXCEPTION_H