[#66678] [ruby-trunk - Feature #10481] Add "if" and "unless" clauses to rescue statements — alex@...
Issue #10481 has been updated by Alex Boyd.
3 messages
2014/12/04
[#66762] Re: [ruby-changes:36667] normal:r48748 (trunk): struct: avoid all O(n) behavior on access — Tanaka Akira <akr@...>
2014-12-10 0:44 GMT+09:00 normal <ko1@atdot.net>:
3 messages
2014/12/10
[#66851] [ruby-trunk - Feature #10585] struct: speedup struct.attr = v for first 10 attributes and struct[:attr] for big structs — funny.falcon@...
Issue #10585 has been updated by Yura Sokolov.
3 messages
2014/12/15
[#67126] Ruby 2.2.0 Released — "NARUSE, Yui" <naruse@...>
We are pleased to announce the release of Ruby 2.2.0.
8 messages
2014/12/25
[#67128] Re: Ruby 2.2.0 Released
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2014/12/25
I can't install it in any of our Ubuntu servers using rbenv:
[#67129] Re: Ruby 2.2.0 Released
— SHIBATA Hiroshi <shibata.hiroshi@...>
2014/12/25
> I can't install it in any of our Ubuntu servers using rbenv:
[ruby-core:67177] [ruby-trunk - Feature #10481] Add "if" and "unless" clauses to rescue statements
From:
alex@...
Date:
2014-12-28 10:28:49 UTC
List:
ruby-core #67177
Issue #10481 has been updated by Alex Boyd.
Any update on this? (Or is this just a matter of more people getting around to giving it due consideration before merging?)
----------------------------------------
Feature #10481: Add "if" and "unless" clauses to rescue statements
https://bugs.ruby-lang.org/issues/10481#change-50663
* Author: Alex Boyd
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category:
* Target version:
----------------------------------------
I'd like to propose a syntax change: allow boolean "if" and "unless" clauses to follow a rescue statement.
Consider the following:
~~~ruby
begin
...
rescue SomeError => e
if e.error_code == 1
...handle error...
else
raise
end
end
~~~
This is a fairly common way of dealing with exceptions where some condition above and beyond the exception's type determines whether the exception should be rescued. It's verbose, though, and it's not obvious at first glance exactly what conditions are being rescued, especially if "...handle error..." is more than a few lines long. I propose that the following be allowed:
~~~ruby
begin
...
rescue SomeError => e if e.error_code == 1
...handle error...
end
~~~
"unless" would, of course, be allowed as well:
~~~ruby
begin
...
rescue SomeError => e unless e.error_code == 2
...handle error...
end
~~~
A rescue statement whose boolean condition failed would be treated the same as if the exception being raised didn't match the exception being rescued, and move on to the next rescue statement:
~~~ruby
begin
...
rescue SomeError => e if e.error_code == 1
...handle error code 1...
rescue SomeError => e if e.error_code == 2
...handle error code 2...
end
~~~
And finally, catch-all rescue statements would be allowed as well:
~~~ruby
begin
...
rescue => e if e.message == "some error"
...handle error...
end
~~~
---Files--------------------------------
rescue-conditions.diff (6.76 KB)
rescue-conditions.diff (6.57 KB)
smime.p7s (4.78 KB)
--
https://bugs.ruby-lang.org/