Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored out the custom way of preserving an original exception #1

Merged
merged 1 commit into from
Mar 6, 2018
Merged

Refactored out the custom way of preserving an original exception #1

merged 1 commit into from
Mar 6, 2018

Conversation

kpumuk
Copy link
Contributor

@kpumuk kpumuk commented Mar 6, 2018

Ruby starting with 2.1 has an easy way to track the original exception, or cause.

begin
  begin
    raise ArgumentError, "Testing"
  rescue
    raise RuntimeError, "Really"
  end
rescue => e
  puts e.inspect
  puts e.cause.inspect
end

#<RuntimeError: Really>
#<ArgumentError: Testing>

Ruby starting with 2.1 has an easy way to track the original exception, or [`cause`](https://ruby-doc.org/core-2.1.0/Exception.html#method-i-cause).

```ruby
begin
  begin
    raise ArgumentError, "Testing"
  rescue
    raise RuntimeError, "Really"
  end
rescue => e
  puts e.inspect
  puts e.cause.inspect
end

#<RuntimeError: Really>
#<ArgumentError: Testing>
```
@philnash philnash merged commit 27b094c into philnash:master Mar 6, 2018
@philnash
Copy link
Owner

philnash commented Mar 6, 2018

Thanks! I did not know this. Isn't Ruby lovely!

@kpumuk
Copy link
Contributor Author

kpumuk commented Mar 6, 2018

👍

@kpumuk kpumuk deleted the dmytro/refactoring branch March 7, 2018 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants