Project

General

Profile

Actions

Feature #20164

open

Add Exception#deconstruct_keys

Added by Dan0042 (Daniel DeLorme) 11 months ago. Updated 10 months ago.

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

Description

It would be convenient to perform pattern matching with exception classes. So Exception#deconstruct_keys should return a hash with :message (original_message) as well as any other keys specific to the exception subclass.

Examples:

begin
  #code
rescue => err
  case err
  in StandardError(message: /Permission denied/) 
    abort "please select a different file"
  in NameError(name: :foo)
    retry if require "foo_helper
  else
    raise
  end
end
Actions

Also available in: Atom PDF

Like3
Like0Like0