Skip to content

SystemExit behavior should be extended to its subclasses #2128

@knu

Description

@knu

Raising an instance of an exception class that inherits SystemExit results in normal exception handling. It looks like the default exception handler checks if exception.equal?(SystemExit) instead of exception.is_a?(SystemExit) to decide whether it should dump a backtrace and exit with 1 or silently exit the process with a given status code.

% RBENV_VERSION=truffleruby+graalvm-20.2.0 ruby -ve 'raise SystemExit.new(3)'; echo $?
truffleruby 20.2.0, like ruby 2.6.6, GraalVM CE Native [x86_64-darwin]
3

% RBENV_VERSION=truffleruby+graalvm-20.2.0 ruby -ve 'class MyExit < SystemExit; end; raise MyExit.new(3)'; echo $?
truffleruby 20.2.0, like ruby 2.6.6, GraalVM CE Native [x86_64-darwin]
-e:1:in `<main>': MyExit (MyExit)
1

Here's how MRI works:

% RBENV_VERSION=2.7.2 ruby -ve 'class MyExit < SystemExit; end; raise MyExit.new(3)'; echo $?
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
3

% RBENV_VERSION=2.7.2 ruby -ve 'raise SystemExit.new(3)'; echo $?
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
3

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions