Project

General

Profile

Actions

Feature #5818

closed

Feature: Raiseable

Added by kstephens (Kurt Stephens) over 10 years ago. Updated over 10 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

= Proposal

The ability to raise any object that is a Raiseable.

= Problem

  • The Exception subclass hierarchy is well-established.
  • CRuby does not allow any object that behaves as an Exception to be raised, it must be a subclass of Exception.
  • 3rd-party code often rescues Exception; e.g. for error recovery, retry and/or logging.
  • Users need the ability to raise objects that would not normally be rescued by any code;
    e.g.: hard timeouts or custom signal handlers in an application.

= Solution

  • A "Raiseable" module implements all of the methods currently defined in Exception.
  • Exception class includes Raiseable module.
  • ruby/eval.c: make_exception() asserts rb_obj_is_kind_of(mesg, rb_mRaiseable),
    instead of rb_obj_is_kind_of(mesg, rb_cException).
  • Users should avoid "rescue Raiseable" in usual circumstances.

= Other Ideas not implemented here:

  • Remove the obj_is_kind_of(mesg, rb_mRaiseable) restriction to allow pure duck-typing.
  • Clean up the ivar names (@bt (Bernd Homuth), @mesg) and method names (set_backtrace).

= Example

(({
raiseable = Class.new do
include Raiseable
def self.exception *args; new *args; end
end

begin
  raise raiseable, "this must be handled"
  assert(false)
rescue Exception
  assert(false)
rescue Raiseable
  assert(true)
end

}))


Files

raiseable.diff (4.09 KB) raiseable.diff kstephens (Kurt Stephens), 12/28/2011 08:17 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #5856: Feature: Raise any objectRejectedmatz (Yukihiro Matsumoto)01/07/2012Actions
Actions

Also available in: Atom PDF