Project

General

Profile

Actions

Feature #19620

open

allow non-module rescue filters that implement the === opertor

Added by bughit (bug hit) 12 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:113363]

Description

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.

begin
  raise 'foo error'
rescue ->e{e.message =~ /foo/}
  p e.message
end

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4438: rescue args type check omittedClosedko1 (Koichi Sasada)02/24/2011Actions
Actions #1

Updated by byroot (Jean Boussier) 12 months ago

  • Related to Bug #4438: rescue args type check omitted added
Actions

Also available in: Atom PDF

Like0
Like0