Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Exception.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22 #ifndef _Exception_hh_
23 #define _Exception_hh_
24 
25 #include <exception>
26 #include <sstream>
27 #include <iostream>
28 
29 #ifdef WIN32
30 /** disable vc++ .net warning 4290 stating that exception types are not
31  checked */
32 /// \todo never disabled warnign in headers because of the global side effect (jw)
33 # pragma warning( disable : 4290 )
34 #endif
35 
36 namespace BIAS {
37 
38  /** macro throwing a BaseException using stream as argument,
39  i.e. BEXCEPTION("variable 'a' has content "<<a) */
40 #ifdef BIAS_DEBUG
41 # define BEXCEPTION(arg)\
42  { \
43  std::ostringstream os;\
44  os << __FILE__ << ":" << __LINE__ <<" : "<< arg;\
45  throw BIAS::FatalException(os.str().c_str());\
46  }
47 #else
48 # define BEXCEPTION(arg)\
49  { \
50  std::ostringstream os;\
51  os << arg;\
52  throw BIAS::FatalException(os.str().c_str());\
53 }
54 #endif
55 
56 #ifdef BIAS_DEBUG
57 # define BEXCEPTION_NONFATAL(arg)\
58  { \
59  std::ostringstream os;\
60  os << __FILE__ << ":" << __LINE__ <<" : "<< arg;\
61  throw BIAS::NonFatalException(os.str().c_str());\
62  }
63 #else
64 # define BEXCEPTION_NONFATAL(arg)\
65  { \
66  std::ostringstream os;\
67  os << arg;\
68  throw BIAS::NonFatalException(os.str().c_str());\
69 }
70 #endif
71 
72 
73 
74  /** @class BaseException
75  @brief generic exception
76  @author woelk 01/2006 */
78  : public std::exception
79  {
80  public:
81  BaseException(const char *error_message) throw()
82  {
83  Message_ = error_message;
84  std::cerr << "exception raised: \""<<Message_<<"\"\n";
85  }
86 
87  BaseException(const std::string &error_message) throw()
88  {
89  Message_ = error_message;
90  std::cerr << "exception raised: \""<<Message_<<"\"\n";
91  }
92 
93  ~BaseException() throw() {};
94 
95  virtual const std::string& What() const throw()
96  { return Message_; }
97 
98  /** Returns a C-style character string describing the general cause
99  of the current error. */
100  virtual const char* what() const throw()
101  { return Message_.c_str(); }
102 
103 
104  protected:
105  std::string Message_;
106  };
107 
108 
109  /** @class NonFatalException
110  @brief non fatal exception
111  @author woelk 01/2006 */
113  : public BaseException
114  {
115  public:
116  NonFatalException(const char *error_message) throw()
117  : BaseException(error_message)
118  {}
119 
120  NonFatalException(const std::string &error_message) throw()
121  : BaseException(error_message)
122  {}
123 
124  ~NonFatalException() throw() {};
125  };
126 
127 
128  /** @class FatalException
129  @brief fatal exception
130  @author woelk 01/2006 */
132  : public BaseException
133  {
134  public:
135  FatalException(const char *error_message) throw()
136  : BaseException(error_message)
137  {}
138 
139  FatalException(const std::string &error_message) throw()
140  : BaseException(error_message)
141  {}
142 
143  ~FatalException() throw() {};
144  };
145 
146 } // namespace
147 
148 #endif // _Exception_hh_
FatalException(const char *error_message)
Definition: Exception.hh:135
fatal exception
Definition: Exception.hh:131
FatalException(const std::string &error_message)
Definition: Exception.hh:139
BaseException(const char *error_message)
Definition: Exception.hh:81
non fatal exception
Definition: Exception.hh:112
BaseException(const std::string &error_message)
Definition: Exception.hh:87
NonFatalException(const std::string &error_message)
Definition: Exception.hh:120
NonFatalException(const char *error_message)
Definition: Exception.hh:116
virtual const char * what() const
Returns a C-style character string describing the general cause of the current error.
Definition: Exception.hh:100
std::string Message_
Definition: Exception.hh:105
generic exception
Definition: Exception.hh:77
virtual const std::string & What() const
Definition: Exception.hh:95