---
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
---
B904.py:10:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
 8 | except ValueError:
 9 |     if "abc":
10 |         raise TypeError
   |         ^^^^^^^^^^^^^^^ B904
11 |     raise UserWarning
12 | except AssertionError:
   |

B904.py:11:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
 9 |     if "abc":
10 |         raise TypeError
11 |     raise UserWarning
   |     ^^^^^^^^^^^^^^^^^ B904
12 | except AssertionError:
13 |     raise  # Bare `raise` should not be an error
   |

B904.py:16:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
14 | except Exception as err:
15 |     assert err
16 |     raise Exception("No cause here...")
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
17 | except BaseException as err:
18 |     raise err
   |

B904.py:20:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
18 |     raise err
19 | except BaseException as err:
20 |     raise some_other_err
   |     ^^^^^^^^^^^^^^^^^^^^ B904
21 | finally:
22 |     raise Exception("Nothing to chain from, so no warning here")
   |

B904.py:63:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
61 | except Exception as e:
62 |     if ...:
63 |         raise RuntimeError("boom!")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
64 |     else:
65 |         raise RuntimeError("bang!")
   |

B904.py:65:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
63 |         raise RuntimeError("boom!")
64 |     else:
65 |         raise RuntimeError("bang!")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
   |

B904.py:73:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
   |
71 |     match 0:
72 |         case 0:
73 |             raise RuntimeError("boom!")
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904
   |


