[ruby-core:75052] [Ruby trunk Bug#12302] at_exit status status is changed by raising/rescueing a exception in at_exit

From: dunaivad@...
Date: 2016-04-20 22:27:02 UTC
List: ruby-core #75052
Issue #12302 has been updated by Winchester Winchester.


The postings on your site are always excellent. Thanks for the great share and keep up http://www.write-an-essay.org/         
 this great work! All the best to you. <a href="http://www.write-an-essay.org/">write-an-essay.org</a>


----------------------------------------
Bug #12302: at_exit status status is changed by raising/rescueing a exception in at_exit
https://bugs.ruby-lang.org/issues/12302#change-58174

* Author: Michael Grosser
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
~~~
at_exit do
  puts "1 #{$!}"
end

at_exit do
  puts "2 #{$!}"
  raise 'x' rescue nil
end

at_exit do
  puts "3 #{$!}"
  exit 1
end
~~~

Nr 3 runs first and exits 1 ... Nr2 receives the correct exit status ... but using raise/rescue there overrides $1 and Nr 1 thinks it is a clean exit ...

seems semi related to https://bugs.ruby-lang.org/issues/5218 ... ideally the at_exit block should restore the previous $! ... or give some other way of knowing the exit status like passing it to the block

~~~
at_exit do |exception}
   ...
end
~~~



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next