The ability to raise any object that is a Raiseable.
- 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.
- 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).
raiseable = Class.new do
def self.exception *args; new *args; end
begin raise raiseable, "this must be handled" assert(false) rescue Exception assert(false) rescue Raiseable assert(true) end
Updated by kstephens (Kurt Stephens) over 11 years ago
Actions #2 [ruby-core:41836]
Updated by matz (Yukihiro Matsumoto) over 11 years ago
Separate the proposal into two: (a) allow non-Exception object to be raised. (b) Raiseable. And I will refuse (b). Currently, I see no good reason for (a), but you can try to persuade me.
Actions #3 [ruby-core:41981]
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Status changed from Open to Rejected