]> Creatis software - gdcm.git/blob - src/gdcmException.h
ajout namespace std pour les string sous Windows
[gdcm.git] / src / gdcmException.h
1 // gdcm.h
2
3 // gdcmlib Intro:  
4 // * gdcmlib is a library dedicated to reading and writing dicom files.
5 // * LGPL for the license
6 // * lightweigth as opposed to CTN or DCMTK which come bundled which try
7 //   to implement the full DICOM standard (networking...). gdcmlib concentrates
8 //   on reading and writing
9 // * Formats: this lib should be able to read ACR-NEMA v1 and v2, Dicom v3 (as
10 //   stated in part10). [cf dcmtk/dcmdata/docs/datadict.txt]
11 // * Targeted plateforms: Un*xes and Win32/VC++6.0
12 //
13 //
14
15 #ifndef GDCM_EXCEPTION_H
16 #define GDCM_EXCEPTION_H
17
18 #include <string>
19 #include <iostream>
20 #include <exception>
21 using namespace std;
22
23 #ifdef _MSC_VER
24 #define GDCM_EXPORT __declspec( dllexport )
25 #else
26 #define GDCM_EXPORT
27 #endif
28
29 /**
30  * Any exception thrown in the gdcm library
31  */
32 class GDCM_EXPORT gdcmException : public exception {
33  protected:
34   /// error message
35   string from;
36   /// error message
37   string error;
38
39  public:
40   /**
41    * Builds an exception with minimal information: name of the thrower
42    * method and error message
43    *
44    * @param from name of the thrower
45    * @param error error description string
46    */
47   explicit gdcmException(const string &from, const string &error = "")
48     throw();
49   
50
51   /**
52    * virtual destructor makes this class dynamic
53    */
54   virtual ~gdcmException() {
55   }
56   
57   /// returns error message
58   const string &getError(void) const throw() {
59     return error;
60   }
61
62   /// returns exception name string
63   operator const char *() const throw();
64
65   /// returns exception name string (overloads std::exception::what)
66   virtual const char *what() const throw() {
67     return (const char *) *this;
68   }
69
70
71   /// exception caught within exception class: print error message and die
72   static void fatal(const char *from) throw();
73
74   /// try to discover this (dynamic) class name
75   virtual string getName() const throw();
76
77   friend ostream& operator<<(ostream &os, const gdcmException &e);
78   
79 };
80
81
82 /** prints exception stack on output stream
83  * @param os output stream
84  * @param e exception to print
85  * @returns output stream os
86  */
87 ostream& operator<<(ostream &os, const gdcmException &e);
88
89
90 /**
91  * File error exception thrown in the gdcm library
92  */
93 class GDCM_EXPORT gdcmFileError : public gdcmException {
94  public:
95   /**
96    * Builds an file-related exception with minimal information: name of
97    * the thrower method and error message
98    *
99    * @param from name of the thrower
100    * @param error error description string
101    */
102   explicit gdcmFileError(const string &from,
103                          const string &error = "File error")
104     throw() : gdcmException(from, error) {
105   }
106 };
107
108
109
110
111 /**
112  * Invalid file format exception
113  */
114 class GDCM_EXPORT gdcmFormatError : public gdcmException {
115  public:
116   /**
117    * Builds an file-related exception with minimal information: name of
118    * the thrower method and error message
119    *
120    * @param from name of the thrower
121    * @param error error description string
122    */
123   explicit gdcmFormatError(const string &from,
124                            const string &error = "Invalid file format error")
125     throw() : gdcmException(from, error) {
126   }
127 };
128
129
130 #endif // GDCM_EXCEPTION_H