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 * 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);
62 //-----------------------------------------------------------------------------
64 * File error exception thrown in the gdcm library
66 class GDCM_EXPORT gdcmFileError : public gdcmException {
69 * Builds an file-related exception with minimal information: name of
70 * the thrower method and error message
72 * @param from name of the thrower
73 * @param error error description string
75 explicit gdcmFileError(const std::string &from,
76 const std::string &error = "File error")
77 throw() : gdcmException(from, error) {
82 //-----------------------------------------------------------------------------
84 * Invalid file format exception
86 class GDCM_EXPORT gdcmFormatError : public gdcmException {
89 * Builds an file-related exception with minimal information: name of
90 * the thrower method and error message
92 * @param from name of the thrower
93 * @param error error description string
95 explicit gdcmFormatError(const std::string &from,
96 const std::string &error = "Invalid file format error")
97 throw() : gdcmException(from, error) {
101 //-----------------------------------------------------------------------------
102 /* prints exception stack on output stream
103 * @param os output stream
104 * @param e exception to print
105 * @returns output stream os
107 std::ostream& operator<<(std::ostream &os, const gdcmException &e);
109 //-----------------------------------------------------------------------------
110 #endif // GDCM_EXCEPTION_H