Permalink
Browse files

Merge pull request #91 from samg/master

Correct some erreoneous information about ruby execption handling.
  • Loading branch information...
2 parents 95f7e7e + 1b0fd8f commit f9e8dd62a403def574480dda827e08bcd1c4c402 @bbatsov bbatsov committed Apr 6, 2012
Showing with 19 additions and 6 deletions.
  1. +19 −6 README.md
View
25 README.md
@@ -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

0 comments on commit f9e8dd6

Please sign in to comment.