[ruby-core:113363] [Ruby master Feature#19620] allow non-module rescue filters that implement the === opertor
From:
"bughit (bug hit) via ruby-core" <ruby-core@...>
Date:
2023-04-27 16:44:50 UTC
List:
ruby-core #113363
Issue #19620 has been reported by bughit (bug hit).
----------------------------------------
Feature #19620: allow non-module rescue filters that implement the === opertor
https://bugs.ruby-lang.org/issues/19620
* Author: bughit (bug hit)
* Status: Open
* Priority: Normal
----------------------------------------
```ruby
module FooErrorFilter
def self.===(e)
e.message =~ /foo/
end
end
def foo_error_filter
FooErrorFilter
end
begin
raise 'foo error'
rescue foo_error_filter => e
p e.message
end
```
Filter matching is done via the `===` operator, which is why the rescue filter modules don't need to be exception classes. But they are required to be modules, why? Since the rescue filter object is only used for the `===` operator it should accept any object supporting it. The module restriction seems arbitrary and pointless.
```ruby
begin
raise 'foo error'
rescue ->e{e.message =~ /foo/}
p e.message
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/