153 lines
4.2 KiB
Markdown
153 lines
4.2 KiB
Markdown
[support.contract.violation]
|
||
|
||
# 17 Language support library [[support]](./#support)
|
||
|
||
## 17.10 Contract-violation handling [[support.contract]](support.contract#violation)
|
||
|
||
### 17.10.3 Class contract_violation [support.contract.violation]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4491)
|
||
|
||
The class contract_violation defines the type of objects used to represent
|
||
a contract violation that has been detected
|
||
during the evaluation of a contract assertion
|
||
with a particular evaluation semantic ([[basic.contract.eval]](basic.contract.eval "6.11.2 Evaluation"))[.](#1.sentence-1)
|
||
|
||
Objects of this type can
|
||
be created only by the implementation[.](#1.sentence-2)
|
||
|
||
It isimplementation-defined
|
||
whether the destructor is virtual[.](#1.sentence-3)
|
||
|
||
[ð](#itemdecl:1)
|
||
|
||
`const char* comment() const noexcept;
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4509)
|
||
|
||
*Returns*: Animplementation-definedntmbs in
|
||
the ordinary literal encoding ([[lex.charset]](lex.charset "5.3.1 Character sets"))[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4516)
|
||
|
||
*Recommended practice*: The string returned
|
||
should contain a textual representation
|
||
of the predicate of the violated contract assertion
|
||
or an empty string if
|
||
storing a textual representation is undesired[.](#3.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
The string can represent a
|
||
truncated, reformatted, or summarized rendering of the
|
||
predicate, before or after preprocessing[.](#3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#itemdecl:2)
|
||
|
||
`contracts::detection_mode detection_mode() const noexcept;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4536)
|
||
|
||
*Returns*: The enumerator value
|
||
corresponding to
|
||
the manner in which the contract violation was identified[.](#4.sentence-1)
|
||
|
||
[ð](#itemdecl:3)
|
||
|
||
`exception_ptr evaluation_exception() const noexcept;
|
||
`
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4550)
|
||
|
||
*Returns*: If the contract violation occurred
|
||
because the evaluation of the predicate exited via an exception,
|
||
an exception_ptr object that refers to
|
||
that exception or a copy of that exception;
|
||
otherwise, a null exception_ptr object[.](#5.sentence-1)
|
||
|
||
[ð](#itemdecl:4)
|
||
|
||
`bool is_terminating() const noexcept;
|
||
`
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4566)
|
||
|
||
*Returns*: true if the evaluation semantic is
|
||
a terminating semantic ([[basic.contract.eval]](basic.contract.eval "6.11.2 Evaluation"));
|
||
otherwise, false[.](#6.sentence-1)
|
||
|
||
[ð](#itemdecl:5)
|
||
|
||
`assertion_kind kind() const noexcept;
|
||
`
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4579)
|
||
|
||
*Returns*: The enumerator value
|
||
corresponding to
|
||
the syntactic form of the violated contract assertion[.](#7.sentence-1)
|
||
|
||
[ð](#itemdecl:6)
|
||
|
||
`source_location location() const noexcept;
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4592)
|
||
|
||
*Returns*: A source_location object
|
||
withimplementation-defined
|
||
value[.](#8.sentence-1)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4599)
|
||
|
||
*Recommended practice*: The value returned should be
|
||
a default constructed source_location object
|
||
or a value identifying the violated contract assertion:
|
||
|
||
- [(9.1)](#9.1)
|
||
|
||
When possible,
|
||
if the violated contract assertion was a precondition,
|
||
the source location of the function invocation should be returned[.](#9.1.sentence-1)
|
||
|
||
- [(9.2)](#9.2)
|
||
|
||
Otherwise,
|
||
the source location of the contract assertion should be returned[.](#9.2.sentence-1)
|
||
|
||
[ð](#itemdecl:7)
|
||
|
||
`evaluation_semantic semantic() const noexcept;
|
||
`
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4622)
|
||
|
||
*Returns*: The enumerator value
|
||
corresponding to
|
||
the evaluation semantic with which
|
||
the violated contract assertion was evaluated[.](#10.sentence-1)
|