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 #include <vector>
00016
00017 #include <boost/assert.hpp>
00018
00019
00020 #include <saga/saga/base.hpp>
00021 #include <saga/saga/util.hpp>
00022 #include <saga/saga/error.hpp>
00023 #include <saga/saga/object.hpp>
00024 #include <saga/impl/runtime.hpp>
00025
00026
00027 #if defined(BOOST_MSVC)
00028 #pragma warning(push)
00029 #pragma warning(disable: 4251 4231 4660)
00030 #endif
00031
00033
00034 namespace saga
00035 {
00036 namespace detail
00037 {
00038
00039 SAGA_EXPORT error get_error(std::vector<exception> const&);
00040
00041
00042
00043 SAGA_EXPORT std::string get_message(std::vector<exception> const&);
00044
00045
00046
00047 SAGA_EXPORT std::string get_top_message(std::vector<exception> const&);
00048
00049
00050
00051 SAGA_EXPORT std::vector<std::string> get_all_messages(std::vector<exception> const&);
00052 }
00053
00073 class SAGA_EXCEPTION_EXPORT exception : public std::exception
00074 {
00075 private:
00077 std::string msg_;
00078 std::string fullmsg_;
00079 mutable saga::error err_;
00080 saga::object object_;
00081 std::vector<exception> exceptions_;
00082
00083 friend class saga::impl::exception_list;
00085
00086 public:
00087
00088
00089
00095 exception (saga::object obj, std::string const& m, error e = NoSuccess)
00096 : msg_(""), fullmsg_(""), err_(e), object_(obj)
00097 {
00099 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00100 err_ <= (saga::error)saga::adaptors::Unexpected);
00101
00102
00103
00104 std::string::size_type p = m.find("SAGA(");
00105 if (std::string::npos == p || 0 != p)
00106 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00107 msg_ += m;
00108
00109 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00110 {
00111 if (err_ != (saga::error)saga::adaptors::Success)
00112 std::cerr << "Created exception: " << msg_ << std::endl;
00113 }
00115 }
00116
00122 exception (saga::object obj, std::vector<exception> const& l)
00123 : msg_(detail::get_top_message(l)), fullmsg_(detail::get_message(l)),
00124 err_(detail::get_error(l)), object_(obj),
00125 exceptions_(l)
00126 {
00128 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00129 err_ <= (saga::error)saga::adaptors::Unexpected);
00130
00131 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00132 {
00133 if (err_ != (saga::error)saga::adaptors::Success)
00134 std::cerr << "Created exception: " << fullmsg_ << std::endl;
00135 }
00137 }
00138
00144 explicit exception (std::string const& m, error e = NoSuccess)
00145 : msg_(""), err_(e)
00146 {
00148 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00149 err_ <= (saga::error)saga::adaptors::Unexpected);
00150
00151
00152
00153 std::string::size_type p = m.find("SAGA(");
00154 if (std::string::npos == p || 0 != p)
00155 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00156 msg_ += m;
00157
00158 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00159 {
00160 if (err_ != (saga::error)saga::adaptors::Success)
00161 std::cerr << "Created exception: " << msg_ << std::endl;
00162 }
00164 }
00165
00171 explicit exception (std::vector<exception> const& l)
00172 : msg_(detail::get_top_message(l)), fullmsg_(detail::get_message(l)),
00173 err_(detail::get_error(l)), exceptions_(l)
00174 {
00176 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00177 err_ <= (saga::error)saga::adaptors::Unexpected);
00178
00179 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00180 {
00181 if (err_ != (saga::error)saga::adaptors::Success)
00182 std::cerr << "Created exception: " << fullmsg_ << std::endl;
00183 }
00185 }
00186
00189 ~exception() throw() {}
00190
00193 char const* what() const throw()
00194 {
00195 return fullmsg_.empty() ? msg_.c_str() : fullmsg_.c_str();
00196 }
00197
00201 char const* get_message() const throw()
00202 {
00203 return msg_.c_str();
00204 }
00205
00208 saga::error get_error () const throw()
00209 {
00210 return err_;
00211 }
00212
00216 saga::object get_object () const throw()
00217 {
00218 return object_;
00219 }
00220
00223 std::vector<exception> const& get_all_exceptions() const throw()
00224 {
00225 return exceptions_;
00226 }
00227
00232 std::vector<std::string> get_all_messages() const
00233 {
00234 return detail::get_all_messages(exceptions_);
00235 }
00236 };
00237
00239 class SAGA_EXCEPTION_EXPORT not_implemented : public saga::exception
00240 {
00241 public:
00244 not_implemented (saga::object obj, std::string const& m)
00245 : saga::exception(obj, m, NotImplemented)
00246 {}
00247
00248 not_implemented (saga::object obj, std::vector<exception> const& l)
00249 : saga::exception(obj, l)
00250 {}
00251
00254 explicit not_implemented (std::string const& m)
00255 : saga::exception(m, NotImplemented)
00256 {}
00257 };
00258
00260 class SAGA_EXCEPTION_EXPORT parameter_exception : public saga::exception
00261 {
00262 protected:
00265 parameter_exception (saga::object obj, std::string const& m, saga::error e)
00266 : saga::exception(obj, m, e)
00267 {}
00268
00269 parameter_exception (saga::object obj, std::vector<exception> const& l)
00270 : saga::exception(obj, l)
00271 {}
00272
00275 parameter_exception (std::string const& m, saga::error e)
00276 : saga::exception(m, e)
00277 {}
00278 };
00279
00281 class SAGA_EXCEPTION_EXPORT incorrect_url : public saga::parameter_exception
00282 {
00283 public:
00286 incorrect_url (saga::object obj, std::string const& m)
00287 : saga::parameter_exception(obj, m, IncorrectURL)
00288 {}
00289
00290 incorrect_url (saga::object obj, std::vector<exception> const& l)
00291 : saga::parameter_exception(obj, l)
00292 {}
00293
00296 explicit incorrect_url (std::string const& m)
00297 : saga::parameter_exception(m, IncorrectURL)
00298 {}
00299 };
00300
00302 class SAGA_EXCEPTION_EXPORT bad_parameter : public saga::parameter_exception
00303 {
00304 public:
00307 bad_parameter (saga::object obj, std::string const& m)
00308 : saga::parameter_exception(obj, m, BadParameter)
00309 {}
00310
00311 bad_parameter (saga::object obj, std::vector<exception> const& l)
00312 : saga::parameter_exception(obj, l)
00313 {}
00314
00317 explicit bad_parameter (std::string const& m)
00318 : saga::parameter_exception(m, BadParameter)
00319 {}
00320 };
00321
00323 class SAGA_EXCEPTION_EXPORT state_exception : public saga::exception
00324 {
00325 protected:
00328 state_exception (saga::object obj, std::string const& m, saga::error e)
00329 : saga::exception(obj, m, e)
00330 {}
00331
00332 state_exception (saga::object obj, std::vector<exception> const& l)
00333 : saga::exception(obj, l)
00334 {}
00335
00338 state_exception (std::string const& m, saga::error e)
00339 : saga::exception(m, e)
00340 {}
00341 };
00342
00344 class SAGA_EXCEPTION_EXPORT already_exists : public saga::state_exception
00345 {
00346 public:
00349 already_exists (saga::object obj, std::string const& m)
00350 : saga::state_exception(obj, m, AlreadyExists)
00351 {}
00352
00353 already_exists (saga::object obj, std::vector<exception> const& l)
00354 : saga::state_exception(obj, l)
00355 {}
00356
00359 explicit already_exists (std::string const& m)
00360 : saga::state_exception(m, AlreadyExists)
00361 {}
00362 };
00363
00365 class SAGA_EXCEPTION_EXPORT does_not_exist : public saga::state_exception
00366 {
00367 public:
00370 does_not_exist (saga::object obj, std::string const& m)
00371 : saga::state_exception(obj, m, DoesNotExist)
00372 {}
00373
00374 does_not_exist (saga::object obj, std::vector<exception> const& l)
00375 : saga::state_exception(obj, l)
00376 {}
00377
00380 explicit does_not_exist (std::string const& m)
00381 : saga::state_exception(m, DoesNotExist)
00382 {}
00383 };
00384
00386 class SAGA_EXCEPTION_EXPORT incorrect_state : public saga::state_exception
00387 {
00388 public:
00391 incorrect_state (saga::object obj, std::string const& m)
00392 : saga::state_exception(obj, m, IncorrectState)
00393 {}
00394
00395 incorrect_state (saga::object obj, std::vector<exception> const& l)
00396 : saga::state_exception(obj, l)
00397 {}
00398
00401 explicit incorrect_state (std::string const& m)
00402 : saga::state_exception(m, IncorrectState)
00403 {}
00404 };
00405
00407 class SAGA_EXCEPTION_EXPORT security_exception : public saga::exception
00408 {
00409 protected:
00412 security_exception (saga::object obj, std::string const& m, saga::error e)
00413 : saga::exception(obj, m, e)
00414 {}
00415
00416 security_exception (saga::object obj, std::vector<exception> const& l)
00417 : saga::exception(obj, l)
00418 {}
00419
00422 security_exception (std::string const& m, saga::error e)
00423 : saga::exception(m, e)
00424 {}
00425 };
00426
00428 class SAGA_EXCEPTION_EXPORT permission_denied
00429 : public saga::security_exception
00430 {
00431 public:
00434 permission_denied (saga::object obj, std::string const& m)
00435 : saga::security_exception(obj, m, PermissionDenied)
00436 {}
00437
00438 permission_denied (saga::object obj, std::vector<exception> const& l)
00439 : saga::security_exception(obj, l)
00440 {}
00441
00444 explicit permission_denied (std::string const& m)
00445 : saga::security_exception(m, PermissionDenied)
00446 {}
00447 };
00448
00450 class SAGA_EXCEPTION_EXPORT authorization_failed
00451 : public saga::security_exception
00452 {
00453 public:
00456 authorization_failed (saga::object obj, std::string const& m)
00457 : saga::security_exception(obj, m, AuthorizationFailed)
00458 {}
00459
00460 authorization_failed (saga::object obj, std::vector<exception> const& l)
00461 : saga::security_exception(obj, l)
00462 {}
00463
00466 explicit authorization_failed (std::string const& m)
00467 : saga::security_exception(m, AuthorizationFailed)
00468 {}
00469 };
00470
00472 class SAGA_EXCEPTION_EXPORT authentication_failed
00473 : public saga::security_exception
00474 {
00475 public:
00478 authentication_failed (saga::object obj, std::string const& m)
00479 : saga::security_exception(obj, m, AuthenticationFailed)
00480 {}
00481
00482 authentication_failed (saga::object obj, std::vector<exception> const& l)
00483 : saga::security_exception(obj, l)
00484 {}
00485
00488 explicit authentication_failed (std::string const& m)
00489 : saga::security_exception(m, AuthenticationFailed)
00490 {}
00491 };
00492
00494 class SAGA_EXCEPTION_EXPORT timeout : public saga::state_exception
00495 {
00496 public:
00499 timeout (saga::object obj, std::string const& m)
00500 : saga::state_exception(obj, m, Timeout)
00501 {}
00502
00503 timeout (saga::object obj, std::vector<exception> const& l)
00504 : saga::state_exception(obj, l)
00505 {}
00506
00509 explicit timeout (std::string const& m)
00510 : saga::state_exception(m, Timeout)
00511 {}
00512 };
00513
00515 class SAGA_EXCEPTION_EXPORT no_success : public saga::exception
00516 {
00517 public:
00520 no_success (saga::object obj, std::string const& m)
00521 : saga::exception(obj, m, NoSuccess)
00522 {}
00523
00524 no_success (saga::object obj, std::vector<exception> const& l)
00525 : saga::exception(obj, l)
00526 {}
00527
00530 explicit no_success (std::string const& m)
00531 : saga::exception(m, NoSuccess)
00532 {}
00533 };
00534
00536
00538
00539 namespace adaptors
00540 {
00542 class SAGA_EXCEPTION_EXPORT exception : public saga::exception
00543 {
00544 public:
00545 exception (saga::object obj,
00546 std::string const& name, std::string const& m,
00547 saga::error e = NoSuccess)
00548 : saga::exception (obj, name + ": " + m, e)
00549 {
00550 }
00551
00552 exception (saga::object obj, std::vector<saga::exception> const& l)
00553 : saga::exception (obj, l)
00554 {
00555 }
00556
00557 ~exception (void) throw () {}
00558 };
00559
00561 }
00563
00565 }
00566
00567
00568 #if defined(BOOST_MSVC)
00569 #pragma warning(pop)
00570 #endif
00571
00572 #endif // SAGA_EXCEPTION_HPP
00573