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

Correct some erreoneous information about ruby execption handling. #91

Merged
merged 1 commit into from Apr 6, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions README.md
Expand Up @@ -857,22 +857,35 @@ in *Ruby* now, not in *Python*.
n / d
```

* Avoid rescuing the `Exception` class.
* Avoid rescuing the `Exception` class. This will trap signals and calls to
`exit`, requiring you to `kill -9` the process.

```Ruby
# bad
# bad
begin
# an exception occurs here
rescue
# calls to exit and kill signals will be caught (except kill -9)
exit
rescue Exception
puts "you didn't really want to exit, right?"
# exception handling
end

# still bad
# good
begin
# a blind rescue rescues from StandardError, not Exception as many
# programmers assume.
rescue => e
# exception handling
end

# also good
begin
# an exception occurs here
rescue Exception

rescue StandardError => e
# exception handling
end

```

* Put more specific exceptions higher up the rescue chain, otherwise
Expand Down