Issue #22007 has been updated by Eregon (Benoit Daloze). The reason is `rescue` clauses are evaluated lazily, and stop at the first matching one. I believe this is by design for efficiency. Evaluating every `rescue` clause when not necessary would be some overhead and have potentially unwanted side effects (which could even cause compatibility issues). `rescue` clauses are arbitrary expressions, so they can have arbitrary side effects. We can have e.g. `rescue RuntimeError, some_method_call_returning_a_class => e` and I don't think many would expect `some_method_call_returning_a_class` to be called needlessly. We can also think of the case of not raising any exception: ```ruby begin p :NO_EXCEPTION rescue /why am I NOT allowed/, "if I was allowed before?" => e p e end ``` Should that raise `TypeError`? If yes the overhead of evaluating these `rescue` clauses when there is no exception would be very significant. I would say unacceptable and unexpected. It would be nice indeed if such invalid rescue clauses are caught early, but the performance cost seems clearly not worth it. With appropriate test coverage this shouldn't be much of an issue in practice, it's also rather rare to have multiple rescue clauses. ---------------------------------------- Bug #22007: Inconsistent type checking on rescue https://bugs.ruby-lang.org/issues/22007#change-117066 * Author: zenspider (Ryan Davis) * Status: Open * ruby -v: 4.0.2 * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- this works fine (but I don't think it should): ```ruby begin raise "nope" rescue RuntimeError, /why am I allowed?/, "or me?" => e # yay end ``` whereas this version shows a type error, which seems right: ```ruby begin begin raise "nope" rescue /why am I NOT allowed/, "if I was allowed before?" => e p e end rescue TypeError => te p te end ``` I think all the args on rescue should be checked to be `Module` -- https://bugs.ruby-lang.org/