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

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

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

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

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

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

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

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:79:9
   |
77 | except* Exception as e:
78 |     if ...:
79 |         raise RuntimeError("boom!")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
80 |     else:
81 |         raise RuntimeError("bang!")
   |

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:81:9
   |
79 |         raise RuntimeError("boom!")
80 |     else:
81 |         raise RuntimeError("bang!")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
82 |
83 | try:
   |

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:87:9
   |
85 | except* ValueError:
86 |     if "abc":
87 |         raise TypeError
   |         ^^^^^^^^^^^^^^^
88 |     raise UserWarning
89 | except* AssertionError:
   |

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:88:5
   |
86 |     if "abc":
87 |         raise TypeError
88 |     raise UserWarning
   |     ^^^^^^^^^^^^^^^^^
89 | except* AssertionError:
90 |     raise  # Bare `raise` should not be an error
   |

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:93:5
   |
91 | except* Exception as err:
92 |     assert err
93 |     raise Exception("No cause here...")
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94 | except* BaseException as err:
95 |     raise err
   |

B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
  --> B904.py:97:5
   |
95 |     raise err
96 | except* BaseException as err:
97 |     raise some_other_err
   |     ^^^^^^^^^^^^^^^^^^^^
98 | finally:
99 |     raise Exception("Nothing to chain from, so no warning here")
   |
