|
||||
File indexing completed on 2025-01-18 09:30:25
0001 0002 #ifndef BOOST_CONTRACT_EXCEPTION_HPP_ 0003 #define BOOST_CONTRACT_EXCEPTION_HPP_ 0004 0005 // Copyright (C) 2008-2018 Lorenzo Caminiti 0006 // Distributed under the Boost Software License, Version 1.0 (see accompanying 0007 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). 0008 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html 0009 0010 /** @file 0011 Handle contract assertion failures. 0012 */ 0013 0014 // IMPORTANT: Included by contract_macro.hpp so trivial headers only. 0015 #include <boost/contract/core/config.hpp> 0016 #include <boost/contract/detail/declspec.hpp> // No compile-time overhead. 0017 #include <boost/function.hpp> 0018 #include <boost/config.hpp> 0019 #include <exception> 0020 #include <string> 0021 0022 // NOTE: This code should not change (not even its impl) based on the 0023 // CONTRACT_NO_... macros. For example, preconditions_failure() should still 0024 // all the set precondition failure handler even when NO_PRECONDITIONS is 0025 // #defined, because user code might explicitly call precondition_failure() 0026 // (for whatever reason...). Otherwise, the public API of this lib will change. 0027 0028 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN 0029 // Needed for `std::` prefix to show (but removed via `EXCLUDE_SYMBOLS=std`). 0030 namespace std { 0031 class exception {}; 0032 class bad_cast {}; 0033 } 0034 #endif 0035 0036 namespace boost { namespace contract { 0037 0038 /** 0039 Public base class for all exceptions directly thrown by this library. 0040 0041 This class does not inherit from @c std::exception because exceptions deriving 0042 from this class will do that (inheriting from @c std::exception, 0043 @c std::bad_cast, etc.). 0044 0045 @see @RefClass{boost::contract::assertion_failure}, 0046 @RefClass{boost::contract::bad_virtual_result_cast}, 0047 etc. 0048 */ 0049 class BOOST_CONTRACT_DETAIL_DECLSPEC exception { 0050 public: 0051 /** 0052 Destruct this object. 0053 0054 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0055 */ 0056 virtual ~exception() /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0057 }; 0058 0059 #ifdef BOOST_MSVC 0060 #pragma warning(push) 0061 #pragma warning(disable: 4275) // Bases w/o DLL spec (bad_cast, etc). 0062 #pragma warning(disable: 4251) // Members w/o DLL spec (string for what_). 0063 #endif 0064 0065 /** 0066 Exception thrown when inconsistent return values are passed to overridden 0067 virtual public functions. 0068 0069 This exception is thrown when programmers pass to this library return value 0070 parameters for public function overrides in derived classes that are not 0071 consistent with the return type parameter passed for the virtual public function 0072 being overridden from the base classes. 0073 This allows this library to give more descriptive error messages in such cases 0074 of misuse. 0075 0076 This exception is internally thrown by this library and programmers should not 0077 need to throw it from user code. 0078 0079 @see @RefSect{tutorial.public_function_overrides__subcontracting_, 0080 Public Function Overrides} 0081 */ 0082 class BOOST_CONTRACT_DETAIL_DECLSPEC bad_virtual_result_cast : // Copy (as str). 0083 public std::bad_cast, public boost::contract::exception { 0084 public: 0085 /** 0086 Construct this object with the name of the from- and to- result types. 0087 0088 @param from_type_name Name of the from-type (source of the cast). 0089 @param to_type_name Name of the to-type (destination of the cast). 0090 */ 0091 explicit bad_virtual_result_cast(char const* from_type_name, 0092 char const* to_type_name); 0093 0094 /** 0095 Destruct this object. 0096 0097 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0098 */ 0099 virtual ~bad_virtual_result_cast() 0100 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0101 0102 /** 0103 Description for this error (containing both from- and to- type names). 0104 0105 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0106 */ 0107 virtual char const* what() const 0108 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0109 0110 /** @cond */ 0111 private: 0112 std::string what_; 0113 /** @endcond */ 0114 }; 0115 0116 /** 0117 Exception typically used to report a contract assertion failure. 0118 0119 This exception is thrown by code expanded by @RefMacro{BOOST_CONTRACT_ASSERT} 0120 (but it can also be thrown by user code programmed manually without that macro). 0121 This exception is typically used to report contract assertion failures because 0122 it contains detailed information about the file name, line number, and source 0123 code of the asserted condition (so it can be used by this library to provide 0124 detailed error messages when handling contract assertion failures). 0125 0126 However, any other exception can be used to report a contract assertion failure 0127 (including user-defined exceptions). 0128 This library will call the appropriate contract failure handler function 0129 (@RefFunc{boost::contract::precondition_failure}, etc.) when this or any other 0130 exception is thrown while checking contracts (by default, these failure handler 0131 functions print an error message to @c std::cerr and terminate the program, but 0132 they can be customized to take any other action). 0133 0134 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0135 @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} 0136 */ 0137 class BOOST_CONTRACT_DETAIL_DECLSPEC assertion_failure : // Copy (as str, etc.). 0138 public std::exception, public boost::contract::exception { 0139 public: 0140 /** 0141 Construct this object with file name, line number, and source code text of 0142 an assertion condition (all optional). 0143 0144 This constructor can also be used to specify no information (default 0145 constructor), or to specify only file name and line number but not source 0146 code text (because of the parameter default values). 0147 0148 @param file Name of the file containing the assertion (usually set using 0149 <c>__FILE__</c>). 0150 @param line Number of the line containing the assertion (usually set using 0151 <c>__LINE__</c>). 0152 @param code Text listing the source code of the assertion condition. 0153 */ 0154 explicit assertion_failure(char const* file = "", unsigned long line = 0, 0155 char const* code = ""); 0156 0157 /** 0158 Construct this object only with the source code text of the assertion 0159 condition. 0160 @param code Text listing the source code of the assertion condition. 0161 */ 0162 explicit assertion_failure(char const* code); 0163 0164 /** 0165 Destruct this object. 0166 0167 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0168 */ 0169 virtual ~assertion_failure() 0170 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0171 0172 /** 0173 String describing the failed assertion. 0174 0175 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0176 0177 @return A string formatted similarly to the following: 0178 <c>assertion "`code()`" failed: file "`file()`", line \`line()\`</c> 0179 (where `` indicate execution quotes). 0180 File, line, and code will be omitted from this string if they were 0181 not specified when constructing this object. 0182 */ 0183 virtual char const* what() const 0184 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0185 0186 /** 0187 Name of the file containing the assertion. 0188 0189 @return File name as specified at construction (or @c "" if no file was 0190 specified). 0191 */ 0192 char const* file() const; 0193 0194 /** 0195 Number of the line containing the assertion. 0196 0197 @return Line number as specified at construction (or @c 0 if no line number 0198 was specified). 0199 */ 0200 unsigned long line() const; 0201 0202 /** 0203 Text listing the source code of the assertion condition. 0204 0205 @return Assertion condition source code as specified at construction (or 0206 @c "" if no source code text was specified). 0207 */ 0208 char const* code() const; 0209 0210 /** @cond */ 0211 private: 0212 void init(); 0213 0214 char const* file_; 0215 unsigned long line_; 0216 char const* code_; 0217 std::string what_; 0218 /** @endcond */ 0219 }; 0220 0221 #ifdef BOOST_MSVC 0222 #pragma warning(pop) 0223 #endif 0224 0225 /** 0226 Indicate the kind of operation where the contract assertion failed. 0227 0228 This is passed as a parameter to the assertion failure handler functions. 0229 For example, it might be necessary to know in which operation an assertion 0230 failed to make sure exceptions are never thrown from destructors, not even 0231 when contract failure handlers are programmed by users to throw exceptions 0232 instead of terminating the program. 0233 0234 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure} 0235 */ 0236 enum from { 0237 /** Assertion failed when checking contracts for constructors. */ 0238 from_constructor, 0239 0240 /** Assertion failed when checking contracts for destructors . */ 0241 from_destructor, 0242 0243 /** 0244 Assertion failed when checking contracts for functions (members or not, 0245 public or not). 0246 */ 0247 from_function 0248 }; 0249 0250 /** 0251 Type of assertion failure handler functions (with @c from parameter). 0252 0253 Assertion failure handler functions specified by this type must be functors 0254 returning @c void and taking a single parameter of type 0255 @RefEnum{boost::contract::from}. 0256 For example, this is used to specify contract failure handlers for class 0257 invariants, preconditions, postconditions, and exception guarantees. 0258 0259 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure} 0260 */ 0261 typedef boost::function<void (from)> from_failure_handler; 0262 0263 /** 0264 Type of assertion failure handler functions (without @c from parameter). 0265 0266 Assertion failure handler functions specified by this type must be nullary 0267 functors returning @c void. 0268 For example, this is used to specify contract failure handlers for 0269 implementation checks. 0270 0271 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure} 0272 */ 0273 typedef boost::function<void ()> failure_handler; 0274 0275 /** @cond */ 0276 namespace exception_ { 0277 // Check failure. 0278 0279 BOOST_CONTRACT_DETAIL_DECLSPEC 0280 failure_handler const& set_check_failure_unlocked(failure_handler const& f) 0281 BOOST_NOEXCEPT_OR_NOTHROW; 0282 BOOST_CONTRACT_DETAIL_DECLSPEC 0283 failure_handler const& set_check_failure_locked(failure_handler const& f) 0284 BOOST_NOEXCEPT_OR_NOTHROW; 0285 0286 BOOST_CONTRACT_DETAIL_DECLSPEC 0287 failure_handler get_check_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; 0288 BOOST_CONTRACT_DETAIL_DECLSPEC 0289 failure_handler get_check_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; 0290 0291 BOOST_CONTRACT_DETAIL_DECLSPEC 0292 void check_failure_unlocked() /* can throw */; 0293 BOOST_CONTRACT_DETAIL_DECLSPEC 0294 void check_failure_locked() /* can throw */; 0295 0296 // Precondition failure. 0297 0298 BOOST_CONTRACT_DETAIL_DECLSPEC 0299 from_failure_handler const& set_pre_failure_unlocked( 0300 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0301 BOOST_CONTRACT_DETAIL_DECLSPEC 0302 from_failure_handler const& set_pre_failure_locked( 0303 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0304 0305 BOOST_CONTRACT_DETAIL_DECLSPEC 0306 from_failure_handler get_pre_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; 0307 BOOST_CONTRACT_DETAIL_DECLSPEC 0308 from_failure_handler get_pre_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; 0309 0310 BOOST_CONTRACT_DETAIL_DECLSPEC 0311 void pre_failure_unlocked(from where) /* can throw */; 0312 BOOST_CONTRACT_DETAIL_DECLSPEC 0313 void pre_failure_locked(from where) /* can throw */; 0314 0315 // Postcondition failure. 0316 0317 BOOST_CONTRACT_DETAIL_DECLSPEC 0318 from_failure_handler const& set_post_failure_unlocked( 0319 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0320 BOOST_CONTRACT_DETAIL_DECLSPEC 0321 from_failure_handler const& set_post_failure_locked( 0322 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0323 0324 BOOST_CONTRACT_DETAIL_DECLSPEC 0325 from_failure_handler get_post_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; 0326 BOOST_CONTRACT_DETAIL_DECLSPEC 0327 from_failure_handler get_post_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; 0328 0329 BOOST_CONTRACT_DETAIL_DECLSPEC 0330 void post_failure_unlocked(from where) /* can throw */; 0331 BOOST_CONTRACT_DETAIL_DECLSPEC 0332 void post_failure_locked(from where) /* can throw */; 0333 0334 // Except failure. 0335 0336 BOOST_CONTRACT_DETAIL_DECLSPEC 0337 from_failure_handler const& set_except_failure_unlocked( 0338 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0339 BOOST_CONTRACT_DETAIL_DECLSPEC 0340 from_failure_handler const& set_except_failure_locked( 0341 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0342 0343 BOOST_CONTRACT_DETAIL_DECLSPEC 0344 from_failure_handler get_except_failure_unlocked() 0345 BOOST_NOEXCEPT_OR_NOTHROW; 0346 BOOST_CONTRACT_DETAIL_DECLSPEC 0347 from_failure_handler get_except_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; 0348 0349 BOOST_CONTRACT_DETAIL_DECLSPEC 0350 void except_failure_unlocked(from where) /* can throw */; 0351 BOOST_CONTRACT_DETAIL_DECLSPEC 0352 void except_failure_locked(from where) /* can throw */; 0353 0354 // Old-copy failure. 0355 0356 BOOST_CONTRACT_DETAIL_DECLSPEC 0357 from_failure_handler const& set_old_failure_unlocked( 0358 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0359 BOOST_CONTRACT_DETAIL_DECLSPEC 0360 from_failure_handler const& set_old_failure_locked( 0361 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0362 0363 BOOST_CONTRACT_DETAIL_DECLSPEC 0364 from_failure_handler get_old_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; 0365 BOOST_CONTRACT_DETAIL_DECLSPEC 0366 from_failure_handler get_old_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; 0367 0368 BOOST_CONTRACT_DETAIL_DECLSPEC 0369 void old_failure_unlocked(from where) /* can throw */; 0370 BOOST_CONTRACT_DETAIL_DECLSPEC 0371 void old_failure_locked(from where) /* can throw */; 0372 0373 // Entry invariant failure. 0374 0375 BOOST_CONTRACT_DETAIL_DECLSPEC 0376 from_failure_handler const& set_entry_inv_failure_unlocked( 0377 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0378 BOOST_CONTRACT_DETAIL_DECLSPEC 0379 from_failure_handler const& set_entry_inv_failure_locked( 0380 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0381 0382 BOOST_CONTRACT_DETAIL_DECLSPEC 0383 from_failure_handler get_entry_inv_failure_unlocked() 0384 BOOST_NOEXCEPT_OR_NOTHROW; 0385 BOOST_CONTRACT_DETAIL_DECLSPEC 0386 from_failure_handler get_entry_inv_failure_locked() 0387 BOOST_NOEXCEPT_OR_NOTHROW; 0388 0389 BOOST_CONTRACT_DETAIL_DECLSPEC 0390 void entry_inv_failure_unlocked(from where) /* can throw */; 0391 BOOST_CONTRACT_DETAIL_DECLSPEC 0392 void entry_inv_failure_locked(from where) /* can throw */; 0393 0394 // Exit invariant failure. 0395 0396 BOOST_CONTRACT_DETAIL_DECLSPEC 0397 from_failure_handler const& set_exit_inv_failure_unlocked( 0398 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0399 BOOST_CONTRACT_DETAIL_DECLSPEC 0400 from_failure_handler const&set_exit_inv_failure_locked( 0401 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW; 0402 0403 BOOST_CONTRACT_DETAIL_DECLSPEC 0404 from_failure_handler get_exit_inv_failure_unlocked() 0405 BOOST_NOEXCEPT_OR_NOTHROW; 0406 BOOST_CONTRACT_DETAIL_DECLSPEC 0407 from_failure_handler get_exit_inv_failure_locked() 0408 BOOST_NOEXCEPT_OR_NOTHROW; 0409 0410 BOOST_CONTRACT_DETAIL_DECLSPEC 0411 void exit_inv_failure_unlocked(from where) /* can throw */; 0412 BOOST_CONTRACT_DETAIL_DECLSPEC 0413 void exit_inv_failure_locked(from where) /* can throw */; 0414 } 0415 /** @endcond */ 0416 0417 } } // namespace 0418 0419 /** @cond */ 0420 #ifdef BOOST_CONTRACT_HEADER_ONLY 0421 // NOTE: This header must be included in the middle of this file (because 0422 // its impl depends on both from and assert_failure types). This is not 0423 // ideal, but it is better than splitting this file into multiple 0424 // independent ones because all content in this file is logically related 0425 // from the user prospective. 0426 #include <boost/contract/detail/inlined/core/exception.hpp> 0427 #endif 0428 /** @endcond */ 0429 0430 namespace boost { namespace contract { 0431 0432 // Following must be inline for static linkage (no DYN_LINK and no HEADER_ONLY). 0433 0434 /** 0435 Set failure handler for implementation checks. 0436 0437 Set a new failure handler and returns it. 0438 0439 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0440 0441 @param f New failure handler functor to set. 0442 0443 @return Same failure handler functor @p f passed as parameter (e.g., for 0444 concatenating function calls). 0445 0446 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0447 @RefSect{advanced.implementation_checks, Implementation Checks} 0448 */ 0449 inline failure_handler const& set_check_failure(failure_handler const& f) 0450 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0451 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0452 return exception_::set_check_failure_locked(f); 0453 #else 0454 return exception_::set_check_failure_unlocked(f); 0455 #endif 0456 } 0457 0458 /** 0459 Return failure handler currently set for implementation checks. 0460 0461 This is often called only internally by this library. 0462 0463 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0464 0465 @return A copy of the failure handler currently set. 0466 0467 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0468 @RefSect{advanced.implementation_checks, Implementation Checks} 0469 */ 0470 inline failure_handler get_check_failure() 0471 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0472 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0473 return exception_::get_check_failure_locked(); 0474 #else 0475 return exception_::get_check_failure_unlocked(); 0476 #endif 0477 } 0478 0479 /** 0480 Call failure handler for implementation checks. 0481 0482 This is often called only internally by this library. 0483 0484 @b Throws: This can throw in case programmers specify a failure handler that 0485 throws exceptions on implementation check failures (not the 0486 default). 0487 0488 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0489 @RefSect{advanced.implementation_checks, Implementation Checks} 0490 */ 0491 inline void check_failure() /* can throw */ { 0492 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0493 exception_::check_failure_locked(); 0494 #else 0495 exception_::check_failure_unlocked(); 0496 #endif 0497 } 0498 0499 /** 0500 Set failure handler for preconditions. 0501 0502 Set a new failure handler and returns it. 0503 0504 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0505 0506 @param f New failure handler functor to set. 0507 0508 @return Same failure handler functor @p f passed as parameter (e.g., for 0509 concatenating function calls). 0510 0511 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0512 @RefSect{tutorial.preconditions, Preconditions} 0513 */ 0514 inline from_failure_handler const& set_precondition_failure(from_failure_handler 0515 const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0516 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0517 return exception_::set_pre_failure_locked(f); 0518 #else 0519 return exception_::set_pre_failure_unlocked(f); 0520 #endif 0521 } 0522 0523 /** 0524 Return failure handler currently set for preconditions. 0525 0526 This is often called only internally by this library. 0527 0528 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0529 0530 @return A copy of the failure handler currently set. 0531 0532 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0533 @RefSect{tutorial.preconditions, Preconditions} 0534 */ 0535 inline from_failure_handler get_precondition_failure() 0536 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0537 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0538 return exception_::get_pre_failure_locked(); 0539 #else 0540 return exception_::get_pre_failure_unlocked(); 0541 #endif 0542 } 0543 0544 /** 0545 Call failure handler for preconditions. 0546 0547 This is often called only internally by this library. 0548 0549 @b Throws: This can throw in case programmers specify a failure handler that 0550 throws exceptions on contract assertion failures (not the default). 0551 0552 @param where Operation that failed the contract assertion (when this function 0553 is called by this library, this parameter will never be 0554 @c from_destructor because destructors do not have 0555 preconditions). 0556 0557 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0558 @RefSect{tutorial.preconditions, Preconditions} 0559 */ 0560 inline void precondition_failure(from where) /* can throw */ { 0561 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0562 exception_::pre_failure_locked(where); 0563 #else 0564 exception_::pre_failure_unlocked(where); 0565 #endif 0566 } 0567 0568 /** 0569 Set failure handler for postconditions. 0570 0571 Set a new failure handler and returns it. 0572 0573 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0574 0575 @param f New failure handler functor to set. 0576 0577 @return Same failure handler functor @p f passed as parameter (e.g., for 0578 concatenating function calls). 0579 0580 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0581 @RefSect{tutorial.postconditions, Postconditions} 0582 */ 0583 inline from_failure_handler const& set_postcondition_failure( 0584 from_failure_handler const& f 0585 ) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0586 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0587 return exception_::set_post_failure_locked(f); 0588 #else 0589 return exception_::set_post_failure_unlocked(f); 0590 #endif 0591 } 0592 0593 /** 0594 Return failure handler currently set for postconditions. 0595 0596 This is often called only internally by this library. 0597 0598 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0599 0600 @return A copy of the failure handler currently set. 0601 0602 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0603 @RefSect{tutorial.postconditions, Postconditions} 0604 */ 0605 inline from_failure_handler get_postcondition_failure() 0606 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0607 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0608 return exception_::get_post_failure_locked(); 0609 #else 0610 return exception_::get_post_failure_unlocked(); 0611 #endif 0612 } 0613 0614 /** 0615 Call failure handler for postconditions. 0616 0617 This is often called only internally by this library. 0618 0619 @b Throws: This can throw in case programmers specify a failure handler that 0620 throws exceptions on contract assertion failures (not the default). 0621 0622 @param where Operation that failed the contract assertion (e.g., this might 0623 be useful to program failure handler functors that never throw 0624 from destructors, not even when they are programmed by users to 0625 throw exceptions instead of terminating the program). 0626 0627 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0628 @RefSect{tutorial.postconditions, Postconditions} 0629 */ 0630 inline void postcondition_failure(from where) /* can throw */ { 0631 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0632 exception_::post_failure_locked(where); 0633 #else 0634 exception_::post_failure_unlocked(where); 0635 #endif 0636 } 0637 0638 /** 0639 Set failure handler for exception guarantees. 0640 0641 Set a new failure handler and returns it. 0642 0643 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0644 0645 @param f New failure handler functor to set. 0646 0647 @return Same failure handler functor @p f passed as parameter (e.g., for 0648 concatenating function calls). 0649 0650 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0651 @RefSect{tutorial.exception_guarantees, Exception Guarantees} 0652 */ 0653 inline from_failure_handler const& set_except_failure(from_failure_handler 0654 const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0655 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0656 return exception_::set_except_failure_locked(f); 0657 #else 0658 return exception_::set_except_failure_unlocked(f); 0659 #endif 0660 } 0661 0662 /** 0663 Return failure handler currently set for exception guarantees. 0664 0665 This is often called only internally by this library. 0666 0667 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0668 0669 @return A copy of the failure handler currently set. 0670 0671 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0672 @RefSect{tutorial.exception_guarantees, Exception Guarantees} 0673 */ 0674 inline from_failure_handler get_except_failure() 0675 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0676 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0677 return exception_::get_except_failure_locked(); 0678 #else 0679 return exception_::get_except_failure_unlocked(); 0680 #endif 0681 } 0682 0683 /** 0684 Call failure handler for exception guarantees. 0685 0686 This is often called only internally by this library. 0687 0688 @b Throws: This can throw in case programmers specify a failure handler that 0689 throws exceptions on contract assertion failures (not the default), 0690 however: 0691 0692 @warning When this failure handler is called there is already an active 0693 exception (the one that caused the exception guarantees to be 0694 checked in the first place). 0695 Therefore, programming this failure handler to throw yet another 0696 exception will force C++ to automatically terminate the program. 0697 0698 @param where Operation that failed the contract assertion. 0699 0700 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0701 @RefSect{tutorial.exception_guarantees, Exception Guarantees} 0702 */ 0703 inline void except_failure(from where) /* can throw */ { 0704 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0705 exception_::except_failure_locked(where); 0706 #else 0707 exception_::except_failure_unlocked(where); 0708 #endif 0709 } 0710 0711 /** 0712 Set failure handler for old values copied at body. 0713 0714 Set a new failure handler and returns it. 0715 0716 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0717 0718 @param f New failure handler functor to set. 0719 0720 @return Same failure handler functor @p f passed as parameter (e.g., for 0721 concatenating function calls). 0722 0723 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0724 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body} 0725 */ 0726 inline from_failure_handler const& set_old_failure(from_failure_handler const& 0727 f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0728 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0729 return exception_::set_old_failure_locked(f); 0730 #else 0731 return exception_::set_old_failure_unlocked(f); 0732 #endif 0733 } 0734 0735 /** 0736 Return failure handler currently set for old values copied at body. 0737 0738 This is often called only internally by this library. 0739 0740 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0741 0742 @return A copy of the failure handler currently set. 0743 0744 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0745 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body} 0746 */ 0747 inline from_failure_handler get_old_failure() 0748 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0749 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0750 return exception_::get_old_failure_locked(); 0751 #else 0752 return exception_::get_old_failure_unlocked(); 0753 #endif 0754 } 0755 0756 /** 0757 Call failure handler for old values copied at body. 0758 0759 This is often called only internally by this library. 0760 0761 @b Throws: This can throw in case programmers specify a failure handler that 0762 throws exceptions on contract assertion failures (not the default). 0763 0764 @param where Operation that failed the old value copy (e.g., this might 0765 be useful to program failure handler functors that never throw 0766 from destructors, not even when they are programmed by users to 0767 throw exceptions instead of terminating the program). 0768 0769 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0770 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body} 0771 */ 0772 inline void old_failure(from where) /* can throw */ { 0773 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0774 exception_::old_failure_locked(where); 0775 #else 0776 exception_::old_failure_unlocked(where); 0777 #endif 0778 } 0779 0780 /** 0781 Set failure handler for class invariants at entry. 0782 0783 Set a new failure handler and returns it. 0784 0785 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0786 0787 @param f New failure handler functor to set. 0788 0789 @return Same failure handler functor @p f passed as parameter (e.g., for 0790 concatenating function calls). 0791 0792 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0793 @RefSect{tutorial.class_invariants, Class Invariants}, 0794 @RefSect{extras.volatile_public_functions, 0795 Volatile Public Functions} 0796 */ 0797 inline from_failure_handler const& set_entry_invariant_failure( 0798 from_failure_handler const& f 0799 )/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0800 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0801 return exception_::set_entry_inv_failure_locked(f); 0802 #else 0803 return exception_::set_entry_inv_failure_unlocked(f); 0804 #endif 0805 } 0806 0807 /** 0808 Return failure handler currently set for class invariants at entry. 0809 0810 This is often called only internally by this library. 0811 0812 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0813 0814 @return A copy of the failure handler currently set. 0815 0816 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0817 @RefSect{tutorial.class_invariants, Class Invariants}, 0818 @RefSect{extras.volatile_public_functions, 0819 Volatile Public Functions} 0820 */ 0821 inline from_failure_handler get_entry_invariant_failure() 0822 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0823 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0824 return exception_::get_entry_inv_failure_locked(); 0825 #else 0826 return exception_::get_entry_inv_failure_unlocked(); 0827 #endif 0828 } 0829 0830 /** 0831 Call failure handler for class invariants at entry. 0832 0833 This is often called only internally by this library. 0834 0835 @b Throws: This can throw in case programmers specify a failure handler that 0836 throws exceptions on contract assertion failures (not the default). 0837 0838 @param where Operation that failed the contract assertion (e.g., this might 0839 be useful to program failure handler functors that never throw 0840 from destructors, not even when they are programmed by users to 0841 throw exceptions instead of terminating the program). 0842 0843 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0844 @RefSect{tutorial.class_invariants, Class Invariants}, 0845 @RefSect{extras.volatile_public_functions, 0846 Volatile Public Functions} 0847 */ 0848 inline void entry_invariant_failure(from where) /* can throw */ { 0849 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0850 return exception_::entry_inv_failure_locked(where); 0851 #else 0852 return exception_::entry_inv_failure_unlocked(where); 0853 #endif 0854 } 0855 0856 /** 0857 Set failure handler for class invariants at exit. 0858 0859 Set a new failure handler and returns it. 0860 0861 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0862 0863 @param f New failure handler functor to set. 0864 0865 @return Same failure handler functor @p f passed as parameter (e.g., for 0866 concatenating function calls). 0867 0868 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0869 @RefSect{tutorial.class_invariants, Class Invariants}, 0870 @RefSect{extras.volatile_public_functions, 0871 Volatile Public Functions} 0872 */ 0873 inline from_failure_handler const& set_exit_invariant_failure( 0874 from_failure_handler const& f 0875 ) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0876 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0877 return exception_::set_exit_inv_failure_locked(f); 0878 #else 0879 return exception_::set_exit_inv_failure_unlocked(f); 0880 #endif 0881 } 0882 0883 /** 0884 Return failure handler currently set for class invariants at exit. 0885 0886 This is often called only internally by this library. 0887 0888 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0889 0890 @return A copy of the failure handler currently set. 0891 0892 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0893 @RefSect{tutorial.class_invariants, Class Invariants}, 0894 @RefSect{extras.volatile_public_functions, 0895 Volatile Public Functions} 0896 */ 0897 inline from_failure_handler get_exit_invariant_failure() 0898 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { 0899 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0900 return exception_::get_exit_inv_failure_locked(); 0901 #else 0902 return exception_::get_exit_inv_failure_unlocked(); 0903 #endif 0904 } 0905 0906 /** 0907 Call failure handler for class invariants at exit. 0908 0909 This is often called only internally by this library. 0910 0911 @b Throws: This can throw in case programmers specify a failure handler that 0912 throws exceptions on contract assertion failures (not the default). 0913 0914 @param where Operation that failed the contract assertion (e.g., this might 0915 be useful to program failure handler functors that never throw 0916 from destructors, not even when they are programmed by users to 0917 throw exceptions instead of terminating the program). 0918 0919 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0920 @RefSect{tutorial.class_invariants, Class Invariants}, 0921 @RefSect{extras.volatile_public_functions, 0922 Volatile Public Functions} 0923 */ 0924 inline void exit_invariant_failure(from where) /* can throw */ { 0925 #ifndef BOOST_CONTRACT_DISABLE_THREADS 0926 exception_::exit_inv_failure_locked(where); 0927 #else 0928 exception_::exit_inv_failure_unlocked(where); 0929 #endif 0930 } 0931 0932 /** 0933 Set failure handler for class invariants (at both entry and exit). 0934 0935 This is provided for convenience and it is equivalent to call both 0936 @RefFunc{boost::contract::set_entry_invariant_failure} and 0937 @RefFunc{boost::contract::set_exit_invariant_failure} with the same functor 0938 parameter @p f. 0939 0940 @b Throws: This is declared @c noexcept (or @c throw() before C++11). 0941 0942 @param f New failure handler functor to set for both entry and exit invariants. 0943 0944 @return Same failure handler functor @p f passed as parameter (e.g., for 0945 concatenating function calls). 0946 0947 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}, 0948 @RefSect{tutorial.class_invariants, Class Invariants}, 0949 @RefSect{extras.volatile_public_functions, 0950 Volatile Public Functions} 0951 */ 0952 /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */ 0953 from_failure_handler const& set_invariant_failure(from_failure_handler const& f) 0954 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; 0955 0956 } } // namespace 0957 0958 #endif // #include guard 0959
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |