2 #ifndef BOOST_CONTRACT_EXCEPTION_HPP_
3 #define BOOST_CONTRACT_EXCEPTION_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
11 Handle contract assertion failures.
14 // IMPORTANT: Included by contract_macro.hpp so trivial headers only.
15 #include <boost/contract/core/config.hpp>
16 #include <boost/contract/detail/declspec.hpp> // No compile-time overhead.
17 #include <boost/function.hpp>
18 #include <boost/config.hpp>
22 // NOTE: This code should not change (not even its impl) based on the
23 // CONTRACT_NO_... macros. For example, preconditions_failure() should still
24 // all the set precondition failure handler even when NO_PRECONDITIONS is
25 // #defined, because user code might explicitly call precondition_failure()
26 // (for whatever reason...). Otherwise, the public API of this lib will change.
28 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
29 // Needed for `std::` prefix to show (but removed via `EXCLUDE_SYMBOLS=std`).
36 namespace boost { namespace contract {
39 Public base class for all exceptions directly thrown by this library.
41 This class does not inherit from @c std::exception because exceptions deriving
42 from this class will do that (inheriting from @c std::exception,
43 @c std::bad_cast, etc.).
45 @see @RefClass{boost::contract::assertion_failure},
46 @RefClass{boost::contract::bad_virtual_result_cast},
49 class BOOST_CONTRACT_DETAIL_DECLSPEC exception {
54 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
56 virtual ~exception() /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
61 #pragma warning(disable: 4275) // Bases w/o DLL spec (bad_cast, etc).
62 #pragma warning(disable: 4251) // Members w/o DLL spec (string for what_).
66 Exception thrown when inconsistent return values are passed to overridden
67 virtual public functions.
69 This exception is thrown when programmers pass to this library return value
70 parameters for public function overrides in derived classes that are not
71 consistent with the return type parameter passed for the virtual public function
72 being overridden from the base classes.
73 This allows this library to give more descriptive error messages in such cases
76 This exception is internally thrown by this library and programmers should not
77 need to throw it from user code.
79 @see @RefSect{tutorial.public_function_overrides__subcontracting_,
80 Public Function Overrides}
82 class BOOST_CONTRACT_DETAIL_DECLSPEC bad_virtual_result_cast : // Copy (as str).
83 public std::bad_cast, public boost::contract::exception {
86 Construct this object with the name of the from- and to- result types.
88 @param from_type_name Name of the from-type (source of the cast).
89 @param to_type_name Name of the to-type (destination of the cast).
91 explicit bad_virtual_result_cast(char const* from_type_name,
92 char const* to_type_name);
97 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
99 virtual ~bad_virtual_result_cast()
100 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
103 Description for this error (containing both from- and to- type names).
105 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
107 virtual char const* what() const
108 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
117 Exception typically used to report a contract assertion failure.
119 This exception is thrown by code expanded by @RefMacro{BOOST_CONTRACT_ASSERT}
120 (but it can also be thrown by user code programmed manually without that macro).
121 This exception is typically used to report contract assertion failures because
122 it contains detailed information about the file name, line number, and source
123 code of the asserted condition (so it can be used by this library to provide
124 detailed error messages when handling contract assertion failures).
126 However, any other exception can be used to report a contract assertion failure
127 (including user-defined exceptions).
128 This library will call the appropriate contract failure handler function
129 (@RefFunc{boost::contract::precondition_failure}, etc.) when this or any other
130 exception is thrown while checking contracts (by default, these failure handler
131 functions print an error message to @c std::cerr and terminate the program, but
132 they can be customized to take any other action).
134 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
135 @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}
137 class BOOST_CONTRACT_DETAIL_DECLSPEC assertion_failure : // Copy (as str, etc.).
138 public std::exception, public boost::contract::exception {
141 Construct this object with file name, line number, and source code text of
142 an assertion condition (all optional).
144 This constructor can also be used to specify no information (default
145 constructor), or to specify only file name and line number but not source
146 code text (because of the parameter default values).
148 @param file Name of the file containing the assertion (usually set using
150 @param line Number of the line containing the assertion (usually set using
152 @param code Text listing the source code of the assertion condition.
154 explicit assertion_failure(char const* file = "", unsigned long line = 0,
155 char const* code = "");
158 Construct this object only with the source code text of the assertion
160 @param code Text listing the source code of the assertion condition.
162 explicit assertion_failure(char const* code);
165 Destruct this object.
167 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
169 virtual ~assertion_failure()
170 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
173 String describing the failed assertion.
175 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
177 @return A string formatted similarly to the following:
178 <c>assertion "`code()`" failed: file "`file()`", line \`line()\`</c>
179 (where `` indicate execution quotes).
180 File, line, and code will be omitted from this string if they were
181 not specified when constructing this object.
183 virtual char const* what() const
184 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
187 Name of the file containing the assertion.
189 @return File name as specified at construction (or @c "" if no file was
192 char const* file() const;
195 Number of the line containing the assertion.
197 @return Line number as specified at construction (or @c 0 if no line number
200 unsigned long line() const;
203 Text listing the source code of the assertion condition.
205 @return Assertion condition source code as specified at construction (or
206 @c "" if no source code text was specified).
208 char const* code() const;
226 Indicate the kind of operation where the contract assertion failed.
228 This is passed as a parameter to the assertion failure handler functions.
229 For example, it might be necessary to know in which operation an assertion
230 failed to make sure exceptions are never thrown from destructors, not even
231 when contract failure handlers are programmed by users to throw exceptions
232 instead of terminating the program.
234 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}
237 /** Assertion failed when checking contracts for constructors. */
240 /** Assertion failed when checking contracts for destructors . */
244 Assertion failed when checking contracts for functions (members or not,
251 Type of assertion failure handler functions (with @c from parameter).
253 Assertion failure handler functions specified by this type must be functors
254 returning @c void and taking a single parameter of type
255 @RefEnum{boost::contract::from}.
256 For example, this is used to specify contract failure handlers for class
257 invariants, preconditions, postconditions, and exception guarantees.
259 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}
261 typedef boost::function<void (from)> from_failure_handler;
264 Type of assertion failure handler functions (without @c from parameter).
266 Assertion failure handler functions specified by this type must be nullary
267 functors returning @c void.
268 For example, this is used to specify contract failure handlers for
269 implementation checks.
271 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure}
273 typedef boost::function<void ()> failure_handler;
276 namespace exception_ {
279 BOOST_CONTRACT_DETAIL_DECLSPEC
280 failure_handler const& set_check_failure_unlocked(failure_handler const& f)
281 BOOST_NOEXCEPT_OR_NOTHROW;
282 BOOST_CONTRACT_DETAIL_DECLSPEC
283 failure_handler const& set_check_failure_locked(failure_handler const& f)
284 BOOST_NOEXCEPT_OR_NOTHROW;
286 BOOST_CONTRACT_DETAIL_DECLSPEC
287 failure_handler get_check_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW;
288 BOOST_CONTRACT_DETAIL_DECLSPEC
289 failure_handler get_check_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW;
291 BOOST_CONTRACT_DETAIL_DECLSPEC
292 void check_failure_unlocked() /* can throw */;
293 BOOST_CONTRACT_DETAIL_DECLSPEC
294 void check_failure_locked() /* can throw */;
296 // Precondition failure.
298 BOOST_CONTRACT_DETAIL_DECLSPEC
299 from_failure_handler const& set_pre_failure_unlocked(
300 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
301 BOOST_CONTRACT_DETAIL_DECLSPEC
302 from_failure_handler const& set_pre_failure_locked(
303 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
305 BOOST_CONTRACT_DETAIL_DECLSPEC
306 from_failure_handler get_pre_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW;
307 BOOST_CONTRACT_DETAIL_DECLSPEC
308 from_failure_handler get_pre_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW;
310 BOOST_CONTRACT_DETAIL_DECLSPEC
311 void pre_failure_unlocked(from where) /* can throw */;
312 BOOST_CONTRACT_DETAIL_DECLSPEC
313 void pre_failure_locked(from where) /* can throw */;
315 // Postcondition failure.
317 BOOST_CONTRACT_DETAIL_DECLSPEC
318 from_failure_handler const& set_post_failure_unlocked(
319 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
320 BOOST_CONTRACT_DETAIL_DECLSPEC
321 from_failure_handler const& set_post_failure_locked(
322 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
324 BOOST_CONTRACT_DETAIL_DECLSPEC
325 from_failure_handler get_post_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW;
326 BOOST_CONTRACT_DETAIL_DECLSPEC
327 from_failure_handler get_post_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW;
329 BOOST_CONTRACT_DETAIL_DECLSPEC
330 void post_failure_unlocked(from where) /* can throw */;
331 BOOST_CONTRACT_DETAIL_DECLSPEC
332 void post_failure_locked(from where) /* can throw */;
336 BOOST_CONTRACT_DETAIL_DECLSPEC
337 from_failure_handler const& set_except_failure_unlocked(
338 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
339 BOOST_CONTRACT_DETAIL_DECLSPEC
340 from_failure_handler const& set_except_failure_locked(
341 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
343 BOOST_CONTRACT_DETAIL_DECLSPEC
344 from_failure_handler get_except_failure_unlocked()
345 BOOST_NOEXCEPT_OR_NOTHROW;
346 BOOST_CONTRACT_DETAIL_DECLSPEC
347 from_failure_handler get_except_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW;
349 BOOST_CONTRACT_DETAIL_DECLSPEC
350 void except_failure_unlocked(from where) /* can throw */;
351 BOOST_CONTRACT_DETAIL_DECLSPEC
352 void except_failure_locked(from where) /* can throw */;
356 BOOST_CONTRACT_DETAIL_DECLSPEC
357 from_failure_handler const& set_old_failure_unlocked(
358 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
359 BOOST_CONTRACT_DETAIL_DECLSPEC
360 from_failure_handler const& set_old_failure_locked(
361 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
363 BOOST_CONTRACT_DETAIL_DECLSPEC
364 from_failure_handler get_old_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW;
365 BOOST_CONTRACT_DETAIL_DECLSPEC
366 from_failure_handler get_old_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW;
368 BOOST_CONTRACT_DETAIL_DECLSPEC
369 void old_failure_unlocked(from where) /* can throw */;
370 BOOST_CONTRACT_DETAIL_DECLSPEC
371 void old_failure_locked(from where) /* can throw */;
373 // Entry invariant failure.
375 BOOST_CONTRACT_DETAIL_DECLSPEC
376 from_failure_handler const& set_entry_inv_failure_unlocked(
377 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
378 BOOST_CONTRACT_DETAIL_DECLSPEC
379 from_failure_handler const& set_entry_inv_failure_locked(
380 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
382 BOOST_CONTRACT_DETAIL_DECLSPEC
383 from_failure_handler get_entry_inv_failure_unlocked()
384 BOOST_NOEXCEPT_OR_NOTHROW;
385 BOOST_CONTRACT_DETAIL_DECLSPEC
386 from_failure_handler get_entry_inv_failure_locked()
387 BOOST_NOEXCEPT_OR_NOTHROW;
389 BOOST_CONTRACT_DETAIL_DECLSPEC
390 void entry_inv_failure_unlocked(from where) /* can throw */;
391 BOOST_CONTRACT_DETAIL_DECLSPEC
392 void entry_inv_failure_locked(from where) /* can throw */;
394 // Exit invariant failure.
396 BOOST_CONTRACT_DETAIL_DECLSPEC
397 from_failure_handler const& set_exit_inv_failure_unlocked(
398 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
399 BOOST_CONTRACT_DETAIL_DECLSPEC
400 from_failure_handler const&set_exit_inv_failure_locked(
401 from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW;
403 BOOST_CONTRACT_DETAIL_DECLSPEC
404 from_failure_handler get_exit_inv_failure_unlocked()
405 BOOST_NOEXCEPT_OR_NOTHROW;
406 BOOST_CONTRACT_DETAIL_DECLSPEC
407 from_failure_handler get_exit_inv_failure_locked()
408 BOOST_NOEXCEPT_OR_NOTHROW;
410 BOOST_CONTRACT_DETAIL_DECLSPEC
411 void exit_inv_failure_unlocked(from where) /* can throw */;
412 BOOST_CONTRACT_DETAIL_DECLSPEC
413 void exit_inv_failure_locked(from where) /* can throw */;
420 #ifdef BOOST_CONTRACT_HEADER_ONLY
421 // NOTE: This header must be included in the middle of this file (because
422 // its impl depends on both from and assert_failure types). This is not
423 // ideal, but it is better than splitting this file into multiple
424 // independent ones because all content in this file is logically related
425 // from the user prospective.
426 #include <boost/contract/detail/inlined/core/exception.hpp>
430 namespace boost { namespace contract {
432 // Following must be inline for static linkage (no DYN_LINK and no HEADER_ONLY).
435 Set failure handler for implementation checks.
437 Set a new failure handler and returns it.
439 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
441 @param f New failure handler functor to set.
443 @return Same failure handler functor @p f passed as parameter (e.g., for
444 concatenating function calls).
446 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
447 @RefSect{advanced.implementation_checks, Implementation Checks}
449 inline failure_handler const& set_check_failure(failure_handler const& f)
450 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
451 #ifndef BOOST_CONTRACT_DISABLE_THREADS
452 return exception_::set_check_failure_locked(f);
454 return exception_::set_check_failure_unlocked(f);
459 Return failure handler currently set for implementation checks.
461 This is often called only internally by this library.
463 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
465 @return A copy of the failure handler currently set.
467 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
468 @RefSect{advanced.implementation_checks, Implementation Checks}
470 inline failure_handler get_check_failure()
471 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
472 #ifndef BOOST_CONTRACT_DISABLE_THREADS
473 return exception_::get_check_failure_locked();
475 return exception_::get_check_failure_unlocked();
480 Call failure handler for implementation checks.
482 This is often called only internally by this library.
484 @b Throws: This can throw in case programmers specify a failure handler that
485 throws exceptions on implementation check failures (not the
488 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
489 @RefSect{advanced.implementation_checks, Implementation Checks}
491 inline void check_failure() /* can throw */ {
492 #ifndef BOOST_CONTRACT_DISABLE_THREADS
493 exception_::check_failure_locked();
495 exception_::check_failure_unlocked();
500 Set failure handler for preconditions.
502 Set a new failure handler and returns it.
504 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
506 @param f New failure handler functor to set.
508 @return Same failure handler functor @p f passed as parameter (e.g., for
509 concatenating function calls).
511 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
512 @RefSect{tutorial.preconditions, Preconditions}
514 inline from_failure_handler const& set_precondition_failure(from_failure_handler
515 const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
516 #ifndef BOOST_CONTRACT_DISABLE_THREADS
517 return exception_::set_pre_failure_locked(f);
519 return exception_::set_pre_failure_unlocked(f);
524 Return failure handler currently set for preconditions.
526 This is often called only internally by this library.
528 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
530 @return A copy of the failure handler currently set.
532 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
533 @RefSect{tutorial.preconditions, Preconditions}
535 inline from_failure_handler get_precondition_failure()
536 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
537 #ifndef BOOST_CONTRACT_DISABLE_THREADS
538 return exception_::get_pre_failure_locked();
540 return exception_::get_pre_failure_unlocked();
545 Call failure handler for preconditions.
547 This is often called only internally by this library.
549 @b Throws: This can throw in case programmers specify a failure handler that
550 throws exceptions on contract assertion failures (not the default).
552 @param where Operation that failed the contract assertion (when this function
553 is called by this library, this parameter will never be
554 @c from_destructor because destructors do not have
557 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
558 @RefSect{tutorial.preconditions, Preconditions}
560 inline void precondition_failure(from where) /* can throw */ {
561 #ifndef BOOST_CONTRACT_DISABLE_THREADS
562 exception_::pre_failure_locked(where);
564 exception_::pre_failure_unlocked(where);
569 Set failure handler for postconditions.
571 Set a new failure handler and returns it.
573 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
575 @param f New failure handler functor to set.
577 @return Same failure handler functor @p f passed as parameter (e.g., for
578 concatenating function calls).
580 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
581 @RefSect{tutorial.postconditions, Postconditions}
583 inline from_failure_handler const& set_postcondition_failure(
584 from_failure_handler const& f
585 ) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
586 #ifndef BOOST_CONTRACT_DISABLE_THREADS
587 return exception_::set_post_failure_locked(f);
589 return exception_::set_post_failure_unlocked(f);
594 Return failure handler currently set for postconditions.
596 This is often called only internally by this library.
598 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
600 @return A copy of the failure handler currently set.
602 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
603 @RefSect{tutorial.postconditions, Postconditions}
605 inline from_failure_handler get_postcondition_failure()
606 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
607 #ifndef BOOST_CONTRACT_DISABLE_THREADS
608 return exception_::get_post_failure_locked();
610 return exception_::get_post_failure_unlocked();
615 Call failure handler for postconditions.
617 This is often called only internally by this library.
619 @b Throws: This can throw in case programmers specify a failure handler that
620 throws exceptions on contract assertion failures (not the default).
622 @param where Operation that failed the contract assertion (e.g., this might
623 be useful to program failure handler functors that never throw
624 from destructors, not even when they are programmed by users to
625 throw exceptions instead of terminating the program).
627 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
628 @RefSect{tutorial.postconditions, Postconditions}
630 inline void postcondition_failure(from where) /* can throw */ {
631 #ifndef BOOST_CONTRACT_DISABLE_THREADS
632 exception_::post_failure_locked(where);
634 exception_::post_failure_unlocked(where);
639 Set failure handler for exception guarantees.
641 Set a new failure handler and returns it.
643 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
645 @param f New failure handler functor to set.
647 @return Same failure handler functor @p f passed as parameter (e.g., for
648 concatenating function calls).
650 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
651 @RefSect{tutorial.exception_guarantees, Exception Guarantees}
653 inline from_failure_handler const& set_except_failure(from_failure_handler
654 const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
655 #ifndef BOOST_CONTRACT_DISABLE_THREADS
656 return exception_::set_except_failure_locked(f);
658 return exception_::set_except_failure_unlocked(f);
663 Return failure handler currently set for exception guarantees.
665 This is often called only internally by this library.
667 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
669 @return A copy of the failure handler currently set.
671 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
672 @RefSect{tutorial.exception_guarantees, Exception Guarantees}
674 inline from_failure_handler get_except_failure()
675 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
676 #ifndef BOOST_CONTRACT_DISABLE_THREADS
677 return exception_::get_except_failure_locked();
679 return exception_::get_except_failure_unlocked();
684 Call failure handler for exception guarantees.
686 This is often called only internally by this library.
688 @b Throws: This can throw in case programmers specify a failure handler that
689 throws exceptions on contract assertion failures (not the default),
692 @warning When this failure handler is called there is already an active
693 exception (the one that caused the exception guarantees to be
694 checked in the first place).
695 Therefore, programming this failure handler to throw yet another
696 exception will force C++ to automatically terminate the program.
698 @param where Operation that failed the contract assertion.
700 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
701 @RefSect{tutorial.exception_guarantees, Exception Guarantees}
703 inline void except_failure(from where) /* can throw */ {
704 #ifndef BOOST_CONTRACT_DISABLE_THREADS
705 exception_::except_failure_locked(where);
707 exception_::except_failure_unlocked(where);
712 Set failure handler for old values copied at body.
714 Set a new failure handler and returns it.
716 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
718 @param f New failure handler functor to set.
720 @return Same failure handler functor @p f passed as parameter (e.g., for
721 concatenating function calls).
723 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
724 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
726 inline from_failure_handler const& set_old_failure(from_failure_handler const&
727 f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
728 #ifndef BOOST_CONTRACT_DISABLE_THREADS
729 return exception_::set_old_failure_locked(f);
731 return exception_::set_old_failure_unlocked(f);
736 Return failure handler currently set for old values copied at body.
738 This is often called only internally by this library.
740 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
742 @return A copy of the failure handler currently set.
744 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
745 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
747 inline from_failure_handler get_old_failure()
748 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
749 #ifndef BOOST_CONTRACT_DISABLE_THREADS
750 return exception_::get_old_failure_locked();
752 return exception_::get_old_failure_unlocked();
757 Call failure handler for old values copied at body.
759 This is often called only internally by this library.
761 @b Throws: This can throw in case programmers specify a failure handler that
762 throws exceptions on contract assertion failures (not the default).
764 @param where Operation that failed the old value copy (e.g., this might
765 be useful to program failure handler functors that never throw
766 from destructors, not even when they are programmed by users to
767 throw exceptions instead of terminating the program).
769 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
770 @RefSect{advanced.old_values_copied_at_body, Old Values Copied at Body}
772 inline void old_failure(from where) /* can throw */ {
773 #ifndef BOOST_CONTRACT_DISABLE_THREADS
774 exception_::old_failure_locked(where);
776 exception_::old_failure_unlocked(where);
781 Set failure handler for class invariants at entry.
783 Set a new failure handler and returns it.
785 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
787 @param f New failure handler functor to set.
789 @return Same failure handler functor @p f passed as parameter (e.g., for
790 concatenating function calls).
792 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
793 @RefSect{tutorial.class_invariants, Class Invariants},
794 @RefSect{extras.volatile_public_functions,
795 Volatile Public Functions}
797 inline from_failure_handler const& set_entry_invariant_failure(
798 from_failure_handler const& f
799 )/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
800 #ifndef BOOST_CONTRACT_DISABLE_THREADS
801 return exception_::set_entry_inv_failure_locked(f);
803 return exception_::set_entry_inv_failure_unlocked(f);
808 Return failure handler currently set for class invariants at entry.
810 This is often called only internally by this library.
812 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
814 @return A copy of the failure handler currently set.
816 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
817 @RefSect{tutorial.class_invariants, Class Invariants},
818 @RefSect{extras.volatile_public_functions,
819 Volatile Public Functions}
821 inline from_failure_handler get_entry_invariant_failure()
822 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
823 #ifndef BOOST_CONTRACT_DISABLE_THREADS
824 return exception_::get_entry_inv_failure_locked();
826 return exception_::get_entry_inv_failure_unlocked();
831 Call failure handler for class invariants at entry.
833 This is often called only internally by this library.
835 @b Throws: This can throw in case programmers specify a failure handler that
836 throws exceptions on contract assertion failures (not the default).
838 @param where Operation that failed the contract assertion (e.g., this might
839 be useful to program failure handler functors that never throw
840 from destructors, not even when they are programmed by users to
841 throw exceptions instead of terminating the program).
843 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
844 @RefSect{tutorial.class_invariants, Class Invariants},
845 @RefSect{extras.volatile_public_functions,
846 Volatile Public Functions}
848 inline void entry_invariant_failure(from where) /* can throw */ {
849 #ifndef BOOST_CONTRACT_DISABLE_THREADS
850 return exception_::entry_inv_failure_locked(where);
852 return exception_::entry_inv_failure_unlocked(where);
857 Set failure handler for class invariants at exit.
859 Set a new failure handler and returns it.
861 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
863 @param f New failure handler functor to set.
865 @return Same failure handler functor @p f passed as parameter (e.g., for
866 concatenating function calls).
868 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
869 @RefSect{tutorial.class_invariants, Class Invariants},
870 @RefSect{extras.volatile_public_functions,
871 Volatile Public Functions}
873 inline from_failure_handler const& set_exit_invariant_failure(
874 from_failure_handler const& f
875 ) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
876 #ifndef BOOST_CONTRACT_DISABLE_THREADS
877 return exception_::set_exit_inv_failure_locked(f);
879 return exception_::set_exit_inv_failure_unlocked(f);
884 Return failure handler currently set for class invariants at exit.
886 This is often called only internally by this library.
888 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
890 @return A copy of the failure handler currently set.
892 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
893 @RefSect{tutorial.class_invariants, Class Invariants},
894 @RefSect{extras.volatile_public_functions,
895 Volatile Public Functions}
897 inline from_failure_handler get_exit_invariant_failure()
898 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ {
899 #ifndef BOOST_CONTRACT_DISABLE_THREADS
900 return exception_::get_exit_inv_failure_locked();
902 return exception_::get_exit_inv_failure_unlocked();
907 Call failure handler for class invariants at exit.
909 This is often called only internally by this library.
911 @b Throws: This can throw in case programmers specify a failure handler that
912 throws exceptions on contract assertion failures (not the default).
914 @param where Operation that failed the contract assertion (e.g., this might
915 be useful to program failure handler functors that never throw
916 from destructors, not even when they are programmed by users to
917 throw exceptions instead of terminating the program).
919 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
920 @RefSect{tutorial.class_invariants, Class Invariants},
921 @RefSect{extras.volatile_public_functions,
922 Volatile Public Functions}
924 inline void exit_invariant_failure(from where) /* can throw */ {
925 #ifndef BOOST_CONTRACT_DISABLE_THREADS
926 exception_::exit_inv_failure_locked(where);
928 exception_::exit_inv_failure_unlocked(where);
933 Set failure handler for class invariants (at both entry and exit).
935 This is provided for convenience and it is equivalent to call both
936 @RefFunc{boost::contract::set_entry_invariant_failure} and
937 @RefFunc{boost::contract::set_exit_invariant_failure} with the same functor
940 @b Throws: This is declared @c noexcept (or @c throw() before C++11).
942 @param f New failure handler functor to set for both entry and exit invariants.
944 @return Same failure handler functor @p f passed as parameter (e.g., for
945 concatenating function calls).
947 @see @RefSect{advanced.throw_on_failures__and__noexcept__, Throw on Failure},
948 @RefSect{tutorial.class_invariants, Class Invariants},
949 @RefSect{extras.volatile_public_functions,
950 Volatile Public Functions}
952 /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
953 from_failure_handler const& set_invariant_failure(from_failure_handler const& f)
954 /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
958 #endif // #include guard