llvm / llvm/llvm-project

[clang-tidy] Add `readability-use-rethrow` check

Open
#189,672 10 comments 1 reaction 1 assignee Claimed by @tharunvk View on GitHub
check-request clang-tidy good first issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

It would be useful to have a clang-tidy check that detects cases where code is clearly trying to rethrow the currently handled exception, but spells it as `throw e;` instead of `throw;`.

For example, code like this is easy to write:

```cpp
try {
f();
} catch (const std::exception &e) {
log(e.what());
throw e;
}
```

but if the intent is to rethrow the active exception, the clearer spelling is:

```cpp
try {
f();
} catch (const std::exception &e) {
log(e.what());
throw;
}
```

The latter expresses the intent directly and avoids the impression that the code is deliberately throwing the caught object as a new exception expression.

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.