catchorg / catchorg/Catch2

CHECK_NOTHROW_RET macro that returns the value inside the parathesis

Open
#2,274 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Description**
```
auto value = CHECK_NOTHROW_RET(function());
```

1. If `function()` throws, it would print the exception just like `CHECK_NOTHROW` currently does.
1. If `function()` does not throw, then it would assign the returned value to `auto value =`.

The main reason I want this is to both get the nice output on failure of `CHECK_NOTHROW` and get the returned value that can be used outside the check.

**Additional context**
Workaround that may or may not provide the same nice Catch2 output.
```
auto value = SomeType{};
CHECK_NOTHROW([&]() { value = functionCall(); }());
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.