From f126d7943a82c0d4da06749131a0d5a0109a53ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 6 Feb 2017 16:08:13 +0100 Subject: [PATCH] Add explanation of THROW assertion limits + using lambda --- docs/assertions.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/assertions.md b/docs/assertions.md index f64fdcfe..b7fba142 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -78,6 +78,20 @@ Expects that an exception of the _specified type_ is thrown during evaluation of Expects that no exception is thrown during evaluation of the expression. + +Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function. + +```cpp +REQUIRE_NOTHROW([&](){ + int i = 1; + int j = 2; + auto k = i + j; + if (k == 3) { + throw 1; + } +}()); +``` + ## Matcher expressions To support Matchers a slightly different form is used. Matchers will be more fully documented elsewhere. *Note that Matchers are still at early stage development and are subject to change.*