00001
00002
00003
00004
00005
00006
00007
00008 #ifndef SAGA_EXCEPTION_HPP
00009 #define SAGA_EXCEPTION_HPP
00010
00011
00012 #include <exception>
00013 #include <iostream>
00014 #include <string>
00015
00016
00017 #include <saga/saga/base.hpp>
00018 #include <saga/saga/util.hpp>
00019 #include <saga/saga/error.hpp>
00020 #include <saga/saga/object.hpp>
00021 #include <saga/impl/runtime.hpp>
00022
00024
00025 namespace saga {
00026
00046 class SAGA_EXCEPTION_EXPORT exception : public std::exception
00047 {
00048 private:
00049 std::string msg_;
00050 mutable saga::error err_;
00051 saga::object object_;
00052
00053 friend class saga::impl::exception_list;
00054
00055 public:
00056
00057
00058
00066 exception (saga::object obj, std::string const& m, error e = NoSuccess)
00067 : msg_(""), err_(e), object_(obj)
00068 {
00069 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00070 err_ <= (saga::error)saga::adaptors::Unexpected);
00071
00072
00073
00074 std::string::size_type p = m.find("SAGA(");
00075 if (std::string::npos == p || 0 != p)
00076 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00077 msg_ += m;
00078
00079 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00080 {
00081 if (err_ != (saga::error)saga::adaptors::Success)
00082 std::cerr << msg_ << std::endl;
00083 }
00084 }
00085
00092 explicit exception (std::string const& m, error e = NoSuccess)
00093 : msg_(""), err_(e)
00094 {
00095 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00096 err_ <= (saga::error)saga::adaptors::Unexpected);
00097
00098
00099
00100 std::string::size_type p = m.find("SAGA(");
00101 if (std::string::npos == p || 0 != p)
00102 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00103 msg_ += m;
00104
00105 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00106 {
00107 if (err_ != (saga::error)saga::adaptors::Success)
00108 std::cerr << msg_ << std::endl;
00109 }
00110 }
00111
00116 ~exception() throw() {}
00117
00122 char const* what() const throw()
00123 {
00124 return (msg_.c_str ());
00125 }
00126
00132 char const* get_message() const throw()
00133 {
00134 return what();
00135 }
00136
00141 saga::error get_error () const
00142 {
00143 return err_;
00144 }
00145
00151 saga::object get_object () const throw()
00152 {
00153 return object_;
00154 }
00155
00156 };
00157
00158
00160 class SAGA_EXCEPTION_EXPORT not_implemented : public saga::exception
00161 {
00162 public:
00167 not_implemented (saga::object obj, std::string const& m)
00168 : saga::exception(obj, m, NotImplemented)
00169 {}
00170
00175 explicit not_implemented (std::string const& m)
00176 : saga::exception(m, NotImplemented)
00177 {}
00178 };
00179
00181 class SAGA_EXCEPTION_EXPORT parameter_exception : public saga::exception
00182 {
00183 protected:
00188 parameter_exception (saga::object obj, std::string const& m, saga::error e)
00189 : saga::exception(obj, m, e)
00190 {}
00191
00196 parameter_exception (std::string const& m, saga::error e)
00197 : saga::exception(m, e)
00198 {}
00199 };
00200
00202 class SAGA_EXCEPTION_EXPORT incorrect_url : public saga::parameter_exception
00203 {
00204 public:
00209 incorrect_url (saga::object obj, std::string const& m)
00210 : saga::parameter_exception(obj, m, IncorrectURL)
00211 {}
00212
00217 explicit incorrect_url (std::string const& m)
00218 : saga::parameter_exception(m, IncorrectURL)
00219 {}
00220 };
00221
00223 class SAGA_EXCEPTION_EXPORT bad_parameter : public saga::parameter_exception
00224 {
00225 public:
00230 bad_parameter (saga::object obj, std::string const& m)
00231 : saga::parameter_exception(obj, m, BadParameter)
00232 {}
00233
00238 explicit bad_parameter (std::string const& m)
00239 : saga::parameter_exception(m, BadParameter)
00240 {}
00241 };
00242
00244 class SAGA_EXCEPTION_EXPORT state_exception : public saga::exception
00245 {
00246 protected:
00251 state_exception (saga::object obj, std::string const& m, saga::error e)
00252 : saga::exception(obj, m, e)
00253 {}
00254
00259 state_exception (std::string const& m, saga::error e)
00260 : saga::exception(m, e)
00261 {}
00262 };
00263
00265 class SAGA_EXCEPTION_EXPORT already_exists : public saga::state_exception
00266 {
00267 public:
00272 already_exists (saga::object obj, std::string const& m)
00273 : saga::state_exception(obj, m, AlreadyExists)
00274 {}
00275
00280 explicit already_exists (std::string const& m)
00281 : saga::state_exception(m, AlreadyExists)
00282 {}
00283 };
00284
00286 class SAGA_EXCEPTION_EXPORT does_not_exist : public saga::state_exception
00287 {
00288 public:
00293 does_not_exist (saga::object obj, std::string const& m)
00294 : saga::state_exception(obj, m, DoesNotExist)
00295 {}
00296
00301 explicit does_not_exist (std::string const& m)
00302 : saga::state_exception(m, DoesNotExist)
00303 {}
00304 };
00305
00307 class SAGA_EXCEPTION_EXPORT incorrect_state : public saga::state_exception
00308 {
00309 public:
00314 incorrect_state (saga::object obj, std::string const& m)
00315 : saga::state_exception(obj, m, IncorrectState)
00316 {}
00317
00322 explicit incorrect_state (std::string const& m)
00323 : saga::state_exception(m, IncorrectState)
00324 {}
00325 };
00326
00328 class SAGA_EXCEPTION_EXPORT security_exception : public saga::exception
00329 {
00330 protected:
00335 security_exception (saga::object obj, std::string const& m, saga::error e)
00336 : saga::exception(obj, m, e)
00337 {}
00338
00343 security_exception (std::string const& m, saga::error e)
00344 : saga::exception(m, e)
00345 {}
00346 };
00347
00349 class SAGA_EXCEPTION_EXPORT permission_denied
00350 : public saga::security_exception
00351 {
00352 public:
00357 permission_denied (saga::object obj, std::string const& m)
00358 : saga::security_exception(obj, m, PermissionDenied)
00359 {}
00360
00365 explicit permission_denied (std::string const& m)
00366 : saga::security_exception(m, PermissionDenied)
00367 {}
00368 };
00369
00371 class SAGA_EXCEPTION_EXPORT authorization_failed
00372 : public saga::security_exception
00373 {
00374 public:
00379 authorization_failed (saga::object obj, std::string const& m)
00380 : saga::security_exception(obj, m, AuthorizationFailed)
00381 {}
00382
00387 explicit authorization_failed (std::string const& m)
00388 : saga::security_exception(m, AuthorizationFailed)
00389 {}
00390 };
00391
00393 class SAGA_EXCEPTION_EXPORT authentication_failed
00394 : public saga::security_exception
00395 {
00396 public:
00401 authentication_failed (saga::object obj, std::string const& m)
00402 : saga::security_exception(obj, m, AuthenticationFailed)
00403 {}
00404
00409 explicit authentication_failed (std::string const& m)
00410 : saga::security_exception(m, AuthenticationFailed)
00411 {}
00412 };
00413
00415 class SAGA_EXCEPTION_EXPORT timeout : public saga::state_exception
00416 {
00417 public:
00422 timeout (saga::object obj, std::string const& m)
00423 : saga::state_exception(obj, m, Timeout)
00424 {}
00425
00430 explicit timeout (std::string const& m)
00431 : saga::state_exception(m, Timeout)
00432 {}
00433 };
00434
00436 class SAGA_EXCEPTION_EXPORT no_success : public saga::exception
00437 {
00438 public:
00443 no_success (saga::object obj, std::string const& m)
00444 : saga::exception(obj, m, NoSuccess)
00445 {}
00446
00451 explicit no_success (std::string const& m)
00452 : saga::exception(m, NoSuccess)
00453 {}
00454 };
00455
00457
00459
00460 namespace adaptors
00461 {
00463 class SAGA_EXCEPTION_EXPORT exception : public saga::exception
00464 {
00465 public:
00466 exception (saga::object obj,
00467 std::string const& name, std::string const& m,
00468 saga::error e = NoSuccess)
00469 : saga::exception (obj, name + ": " + m, e)
00470 {
00471 }
00472
00473 ~exception (void) throw () { }
00474 };
00475
00477 }
00479
00481 }
00482
00483 #endif // SAGA_EXCEPTION_HPP
00484