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:
00076 std::string msg_;
00077 std::string fullmsg_;
00078 mutable saga::error err_;
00079 saga::object object_;
00080 std::vector<exception> exceptions_;
00081
00082 friend class saga::impl::exception_list;
00083
00084 public:
00085
00086
00087
00093 exception (saga::object obj, std::string const& m, error e = NoSuccess)
00094 : msg_(""), fullmsg_(""), err_(e), object_(obj)
00095 {
00096 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00097 err_ <= (saga::error)saga::adaptors::Unexpected);
00098
00099
00100
00101 std::string::size_type p = m.find("SAGA(");
00102 if (std::string::npos == p || 0 != p)
00103 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00104 msg_ += m;
00105
00106 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00107 {
00108 if (err_ != (saga::error)saga::adaptors::Success)
00109 std::cerr << "Created exception: " << msg_ << std::endl;
00110 }
00111 }
00112
00118 exception (saga::object obj, std::vector<exception> const& l)
00119 : msg_(detail::get_top_message(l)), fullmsg_(detail::get_message(l)),
00120 err_(detail::get_error(l)), object_(obj),
00121 exceptions_(l)
00122 {
00123 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00124 err_ <= (saga::error)saga::adaptors::Unexpected);
00125
00126 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00127 {
00128 if (err_ != (saga::error)saga::adaptors::Success)
00129 std::cerr << "Created exception: " << fullmsg_ << std::endl;
00130 }
00131 }
00132
00138 explicit exception (std::string const& m, error e = NoSuccess)
00139 : msg_(""), err_(e)
00140 {
00141 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00142 err_ <= (saga::error)saga::adaptors::Unexpected);
00143
00144
00145
00146 std::string::size_type p = m.find("SAGA(");
00147 if (std::string::npos == p || 0 != p)
00148 msg_ = std::string("SAGA(") + error_names[e] + "): ";
00149 msg_ += m;
00150
00151 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00152 {
00153 if (err_ != (saga::error)saga::adaptors::Success)
00154 std::cerr << "Created exception: " << msg_ << std::endl;
00155 }
00156 }
00157
00163 explicit exception (std::vector<exception> const& l)
00164 : msg_(detail::get_top_message(l)), fullmsg_(detail::get_message(l)),
00165 err_(detail::get_error(l)), exceptions_(l)
00166 {
00167 BOOST_ASSERT(err_ >= (saga::error)saga::adaptors::Success &&
00168 err_ <= (saga::error)saga::adaptors::Unexpected);
00169
00170 SAGA_VERBOSE(SAGA_VERBOSE_LEVEL_INFO)
00171 {
00172 if (err_ != (saga::error)saga::adaptors::Success)
00173 std::cerr << "Created exception: " << fullmsg_ << std::endl;
00174 }
00175 }
00176
00179 ~exception() throw() {}
00180
00183 char const* what() const throw()
00184 {
00185 return fullmsg_.empty() ? msg_.c_str() : fullmsg_.c_str();
00186 }
00187
00191 char const* get_message() const throw()
00192 {
00193 return msg_.c_str();
00194 }
00195
00198 saga::error get_error () const throw()
00199 {
00200 return err_;
00201 }
00202
00206 saga::object get_object () const throw()
00207 {
00208 return object_;
00209 }
00210
00213 std::vector<exception> const& get_all_exceptions() const throw()
00214 {
00215 return exceptions_;
00216 }
00217
00222 std::vector<std::string> get_all_messages() const
00223 {
00224 return detail::get_all_messages(exceptions_);
00225 }
00226 };
00227
00229 class SAGA_EXCEPTION_EXPORT not_implemented : public saga::exception
00230 {
00231 public:
00234 not_implemented (saga::object obj, std::string const& m)
00235 : saga::exception(obj, m, NotImplemented)
00236 {}
00237
00238 not_implemented (saga::object obj, std::vector<exception> const& l)
00239 : saga::exception(obj, l)
00240 {}
00241
00244 explicit not_implemented (std::string const& m)
00245 : saga::exception(m, NotImplemented)
00246 {}
00247 };
00248
00250 class SAGA_EXCEPTION_EXPORT parameter_exception : public saga::exception
00251 {
00252 protected:
00255 parameter_exception (saga::object obj, std::string const& m, saga::error e)
00256 : saga::exception(obj, m, e)
00257 {}
00258
00259 parameter_exception (saga::object obj, std::vector<exception> const& l)
00260 : saga::exception(obj, l)
00261 {}
00262
00265 parameter_exception (std::string const& m, saga::error e)
00266 : saga::exception(m, e)
00267 {}
00268 };
00269
00271 class SAGA_EXCEPTION_EXPORT incorrect_url : public saga::parameter_exception
00272 {
00273 public:
00276 incorrect_url (saga::object obj, std::string const& m)
00277 : saga::parameter_exception(obj, m, IncorrectURL)
00278 {}
00279
00280 incorrect_url (saga::object obj, std::vector<exception> const& l)
00281 : saga::parameter_exception(obj, l)
00282 {}
00283
00286 explicit incorrect_url (std::string const& m)
00287 : saga::parameter_exception(m, IncorrectURL)
00288 {}
00289 };
00290
00292 class SAGA_EXCEPTION_EXPORT bad_parameter : public saga::parameter_exception
00293 {
00294 public:
00297 bad_parameter (saga::object obj, std::string const& m)
00298 : saga::parameter_exception(obj, m, BadParameter)
00299 {}
00300
00301 bad_parameter (saga::object obj, std::vector<exception> const& l)
00302 : saga::parameter_exception(obj, l)
00303 {}
00304
00307 explicit bad_parameter (std::string const& m)
00308 : saga::parameter_exception(m, BadParameter)
00309 {}
00310 };
00311
00313 class SAGA_EXCEPTION_EXPORT state_exception : public saga::exception
00314 {
00315 protected:
00318 state_exception (saga::object obj, std::string const& m, saga::error e)
00319 : saga::exception(obj, m, e)
00320 {}
00321
00322 state_exception (saga::object obj, std::vector<exception> const& l)
00323 : saga::exception(obj, l)
00324 {}
00325
00328 state_exception (std::string const& m, saga::error e)
00329 : saga::exception(m, e)
00330 {}
00331 };
00332
00334 class SAGA_EXCEPTION_EXPORT already_exists : public saga::state_exception
00335 {
00336 public:
00339 already_exists (saga::object obj, std::string const& m)
00340 : saga::state_exception(obj, m, AlreadyExists)
00341 {}
00342
00343 already_exists (saga::object obj, std::vector<exception> const& l)
00344 : saga::state_exception(obj, l)
00345 {}
00346
00349 explicit already_exists (std::string const& m)
00350 : saga::state_exception(m, AlreadyExists)
00351 {}
00352 };
00353
00355 class SAGA_EXCEPTION_EXPORT does_not_exist : public saga::state_exception
00356 {
00357 public:
00360 does_not_exist (saga::object obj, std::string const& m)
00361 : saga::state_exception(obj, m, DoesNotExist)
00362 {}
00363
00364 does_not_exist (saga::object obj, std::vector<exception> const& l)
00365 : saga::state_exception(obj, l)
00366 {}
00367
00370 explicit does_not_exist (std::string const& m)
00371 : saga::state_exception(m, DoesNotExist)
00372 {}
00373 };
00374
00376 class SAGA_EXCEPTION_EXPORT incorrect_state : public saga::state_exception
00377 {
00378 public:
00381 incorrect_state (saga::object obj, std::string const& m)
00382 : saga::state_exception(obj, m, IncorrectState)
00383 {}
00384
00385 incorrect_state (saga::object obj, std::vector<exception> const& l)
00386 : saga::state_exception(obj, l)
00387 {}
00388
00391 explicit incorrect_state (std::string const& m)
00392 : saga::state_exception(m, IncorrectState)
00393 {}
00394 };
00395
00397 class SAGA_EXCEPTION_EXPORT security_exception : public saga::exception
00398 {
00399 protected:
00402 security_exception (saga::object obj, std::string const& m, saga::error e)
00403 : saga::exception(obj, m, e)
00404 {}
00405
00406 security_exception (saga::object obj, std::vector<exception> const& l)
00407 : saga::exception(obj, l)
00408 {}
00409
00412 security_exception (std::string const& m, saga::error e)
00413 : saga::exception(m, e)
00414 {}
00415 };
00416
00418 class SAGA_EXCEPTION_EXPORT permission_denied
00419 : public saga::security_exception
00420 {
00421 public:
00424 permission_denied (saga::object obj, std::string const& m)
00425 : saga::security_exception(obj, m, PermissionDenied)
00426 {}
00427
00428 permission_denied (saga::object obj, std::vector<exception> const& l)
00429 : saga::security_exception(obj, l)
00430 {}
00431
00434 explicit permission_denied (std::string const& m)
00435 : saga::security_exception(m, PermissionDenied)
00436 {}
00437 };
00438
00440 class SAGA_EXCEPTION_EXPORT authorization_failed
00441 : public saga::security_exception
00442 {
00443 public:
00446 authorization_failed (saga::object obj, std::string const& m)
00447 : saga::security_exception(obj, m, AuthorizationFailed)
00448 {}
00449
00450 authorization_failed (saga::object obj, std::vector<exception> const& l)
00451 : saga::security_exception(obj, l)
00452 {}
00453
00456 explicit authorization_failed (std::string const& m)
00457 : saga::security_exception(m, AuthorizationFailed)
00458 {}
00459 };
00460
00462 class SAGA_EXCEPTION_EXPORT authentication_failed
00463 : public saga::security_exception
00464 {
00465 public:
00468 authentication_failed (saga::object obj, std::string const& m)
00469 : saga::security_exception(obj, m, AuthenticationFailed)
00470 {}
00471
00472 authentication_failed (saga::object obj, std::vector<exception> const& l)
00473 : saga::security_exception(obj, l)
00474 {}
00475
00478 explicit authentication_failed (std::string const& m)
00479 : saga::security_exception(m, AuthenticationFailed)
00480 {}
00481 };
00482
00484 class SAGA_EXCEPTION_EXPORT timeout : public saga::state_exception
00485 {
00486 public:
00489 timeout (saga::object obj, std::string const& m)
00490 : saga::state_exception(obj, m, Timeout)
00491 {}
00492
00493 timeout (saga::object obj, std::vector<exception> const& l)
00494 : saga::state_exception(obj, l)
00495 {}
00496
00499 explicit timeout (std::string const& m)
00500 : saga::state_exception(m, Timeout)
00501 {}
00502 };
00503
00505 class SAGA_EXCEPTION_EXPORT no_success : public saga::exception
00506 {
00507 public:
00510 no_success (saga::object obj, std::string const& m)
00511 : saga::exception(obj, m, NoSuccess)
00512 {}
00513
00514 no_success (saga::object obj, std::vector<exception> const& l)
00515 : saga::exception(obj, l)
00516 {}
00517
00520 explicit no_success (std::string const& m)
00521 : saga::exception(m, NoSuccess)
00522 {}
00523 };
00524
00526
00528
00529 namespace adaptors
00530 {
00532 class SAGA_EXCEPTION_EXPORT exception : public saga::exception
00533 {
00534 public:
00535 exception (saga::object obj,
00536 std::string const& name, std::string const& m,
00537 saga::error e = NoSuccess)
00538 : saga::exception (obj, name + ": " + m, e)
00539 {
00540 }
00541
00542 exception (saga::object obj, std::vector<saga::exception> const& l)
00543 : saga::exception (obj, l)
00544 {
00545 }
00546
00547 ~exception (void) throw () {}
00548 };
00549
00551 }
00553
00555 }
00556
00557
00558 #if defined(BOOST_MSVC)
00559 #pragma warning(pop)
00560 #endif
00561
00562 #endif // SAGA_EXCEPTION_HPP
00563