Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #91 from samg/master

Correct some erreoneous information about ruby execption handling.
  • Loading branch information...
commit f9e8dd62a403def574480dda827e08bcd1c4c402 2 parents 95f7e7e + 1b0fd8f
Bozhidar Batsov authored April 06, 2012

Showing 1 changed file with 19 additions and 6 deletions. Show diff stats Hide diff stats

  1. 25  README.md
25  README.md
Source Rendered
@@ -857,22 +857,35 @@ in *Ruby* now, not in *Python*.
857 857
       n / d
858 858
     ```
859 859
   
860  
-* Avoid rescuing the `Exception` class.
  860
+* Avoid rescuing the `Exception` class.  This will trap signals and calls to
  861
+  `exit`, requiring you to `kill -9` the process.
861 862
 
862 863
     ```Ruby
863  
-    # bad 
  864
+    # bad
864 865
     begin
865  
-      # an exception occurs here
866  
-    rescue
  866
+      # calls to exit and kill signals will be caught (except kill -9)
  867
+      exit
  868
+    rescue Exception
  869
+      puts "you didn't really want to exit, right?"
867 870
       # exception handling
868 871
     end
869 872
 
870  
-    # still bad
  873
+    # good
  874
+    begin
  875
+      # a blind rescue rescues from StandardError, not Exception as many
  876
+      # programmers assume.
  877
+    rescue => e
  878
+      # exception handling
  879
+    end
  880
+
  881
+    # also good
871 882
     begin
872 883
       # an exception occurs here
873  
-    rescue Exception
  884
+
  885
+    rescue StandardError => e
874 886
       # exception handling
875 887
     end
  888
+
876 889
     ```
877 890
 
878 891
 * Put more specific exceptions higher up the rescue chain, otherwise

0 notes on commit f9e8dd6

Please sign in to comment.
Something went wrong with that request. Please try again.