Skip to content

Commit

Permalink
Merge pull request rubocop#91 from samg/master
Browse files Browse the repository at this point in the history
Correct some erreoneous information about ruby execption handling.
  • Loading branch information
bbatsov committed Apr 6, 2012
2 parents 040e14a + 976ea55 commit a981261
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit a981261

Please sign in to comment.