1 #ifndef GDCM_EXCEPTION_H
2 #define GDCM_EXCEPTION_H
7 #include "gdcmCommon.h"
10 * Any exception thrown in the gdcm library
12 class GDCM_EXPORT gdcmException : public std::exception {
21 * Builds an exception with minimal information: name of the thrower
22 * method and error message
24 * @param from name of the thrower
25 * @param error error description string
27 explicit gdcmException(const std::string &from, const std::string &error = "")
32 * virtual destructor makes this class dynamic
34 virtual ~gdcmException() throw() {
37 /// returns error message
38 const std::string &getError(void) const throw() {
42 /// returns exception name string
43 operator const char *() const throw();
45 /// returns exception name string (overloads std::exception::what)
46 virtual const char *what() const throw() {
47 return (const char *) *this;
51 /// exception caught within exception class: print error message and die
52 static void fatal(const char *from) throw();
54 /// try to discover this (dynamic) class name
55 virtual std::string getName() const throw();
57 friend std::ostream& operator<<(std::ostream &os, const gdcmException &e);
62 /** prints exception stack on output stream
63 * @param os output stream
64 * @param e exception to print
65 * @returns output stream os
67 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
71 * File error exception thrown in the gdcm library
73 class GDCM_EXPORT gdcmFileError : public gdcmException {
76 * Builds an file-related exception with minimal information: name of
77 * the thrower method and error message
79 * @param from name of the thrower
80 * @param error error description string
82 explicit gdcmFileError(const std::string &from,
83 const std::string &error = "File error")
84 throw() : gdcmException(from, error) {
90 * Invalid file format exception
92 class GDCM_EXPORT gdcmFormatError : public gdcmException {
95 * Builds an file-related exception with minimal information: name of
96 * the thrower method and error message
98 * @param from name of the thrower
99 * @param error error description string
101 explicit gdcmFormatError(const std::string &from,
102 const std::string &error = "Invalid file format error")
103 throw() : gdcmException(from, error) {
108 #endif // GDCM_EXCEPTION_H