catchorg / catchorg/Catch2

Include nested exceptions when Catch2 prints exceptions

Open
#1,939 1 comment 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

# Reproducer
```C++
#include

namespace
{
int get42()
{
try
{
throw std::runtime_error{ "Inner error with root cause details" };
}
catch(const std::exception &)
{
std::throw_with_nested(std::runtime_error{ "Higher level context aware info" });
}
}
} // namespace

TEST_CASE("Reproducer")
{
REQUIRE(42 == get42());
}
```

# Proposed behavior

```shell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reproduce is a Catch v2.11.3 host application.
Run with -? for options

-------------------------------------------------------------------------------
Simple test case, not aware of possibly complicated exception chains
-------------------------------------------------------------------------------
/Reproduce.cpp:18
...............................................................................

/Reproduce.cpp:20: FAILED:
REQUIRE( 42 == get42() )
due to unexpected exception with message:
Higher level context aware info
+ Inner error with root cause details

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed
```

I propose to support exceptions nested to arbitrary depth like this:

```shell
Higher level context aware info
+ Inner error with root cause details
+ More inner
+ Even more inner
+ ...
```

# Current behavior

```shell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reproduce is a Catch v2.11.3 host application.
Run with -? for options

-------------------------------------------------------------------------------
Simple test case, not aware of possibly complicated exception chains
-------------------------------------------------------------------------------
/Reproduce.cpp:18
...............................................................................

/Reproduce.cpp:20: FAILED:
REQUIRE( 42 == get42() )
due to unexpected exception with message:
Higher level context aware info

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed
```

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.