raise-within-try (TRY301)
Derived from the tryceratops linter.
What it does
Checks for raise
statements within try
blocks. The only raise
s
caught are those that throw exceptions caught by the try
statement itself.
Why is this bad?
Raising and catching exceptions within the same try
block is redundant,
as the code can be refactored to avoid the try
block entirely.
Alternatively, the raise
can be moved within an inner function, making
the exception reusable across multiple call sites.
Example
Use instead: