1 | #ifndef XMLIO_EXCEPTION_HPP |
---|
2 | #define XMLIO_EXCEPTION_HPP |
---|
3 | |
---|
4 | #include <sstream> |
---|
5 | //#include "xmlio_std.hpp" |
---|
6 | using namespace std ; |
---|
7 | |
---|
8 | class ex_error |
---|
9 | { |
---|
10 | public : |
---|
11 | string what ; |
---|
12 | ex_error(const string & what_ ) : what(what_) {} ; |
---|
13 | } ; |
---|
14 | |
---|
15 | //class error; |
---|
16 | //ostringstream & operator << (const error & err,char const * str) ; |
---|
17 | //ostringstream & operator << (const error & err,const string & str) ; |
---|
18 | |
---|
19 | |
---|
20 | class error : public ostringstream |
---|
21 | { |
---|
22 | public : |
---|
23 | |
---|
24 | error(const string & where) : ostringstream() |
---|
25 | { |
---|
26 | *this<<"*** Error **** in function : "<<where<<endl<<"------> "<<string("toto") ; |
---|
27 | } ; |
---|
28 | |
---|
29 | error(const char * where) : ostringstream() |
---|
30 | { |
---|
31 | *this<<"Error in function : "<<where<<endl<<"------> " ; |
---|
32 | } ; |
---|
33 | |
---|
34 | ~error() |
---|
35 | { |
---|
36 | std::cerr<< this->str() <<endl ; |
---|
37 | throw(ex_error(this->str())) ; |
---|
38 | } ; |
---|
39 | |
---|
40 | ostringstream & operator << (char const * str) const |
---|
41 | { |
---|
42 | ostringstream * tmp=const_cast <error *>(this) ; |
---|
43 | *tmp<<str ; |
---|
44 | return *tmp ; |
---|
45 | } ; |
---|
46 | |
---|
47 | ostringstream & operator << (const string& str) const |
---|
48 | { |
---|
49 | ostringstream * tmp=const_cast <error *>(this) ; |
---|
50 | *tmp<<str ; |
---|
51 | return *tmp ; |
---|
52 | } ; |
---|
53 | |
---|
54 | } ; |
---|
55 | |
---|
56 | class warning : public ostringstream |
---|
57 | { |
---|
58 | public : |
---|
59 | |
---|
60 | warning(const string & where) : ostringstream() |
---|
61 | { |
---|
62 | *this<<"*** Warning **** in function : "<<where<<endl<<"------> "; |
---|
63 | } ; |
---|
64 | |
---|
65 | warning(const char * where) : ostringstream() |
---|
66 | { |
---|
67 | *this<<"Error in function : "<<where<<endl<<"------> " ; |
---|
68 | } ; |
---|
69 | |
---|
70 | ~warning() |
---|
71 | { |
---|
72 | StdErr<< this->str() <<endl ; |
---|
73 | } ; |
---|
74 | |
---|
75 | ostringstream & operator << (char const * str) const |
---|
76 | { |
---|
77 | ostringstream * tmp=const_cast <warning *>(this) ; |
---|
78 | *tmp<<str ; |
---|
79 | return *tmp ; |
---|
80 | } ; |
---|
81 | |
---|
82 | ostringstream & operator << (const string& str) const |
---|
83 | { |
---|
84 | ostringstream * tmp=const_cast <warning *>(this) ; |
---|
85 | *tmp<<str ; |
---|
86 | return *tmp ; |
---|
87 | } ; |
---|
88 | |
---|
89 | } ; |
---|
90 | |
---|
91 | |
---|
92 | #endif |
---|