changeset 1498:0f326860210e

Merged
author Olivier Delalleau <delallea@iro>
date Thu, 01 Sep 2011 13:35:15 -0400
parents 3d4615ee96a4 (diff) 93b8373c6735 (current diff)
children f82b80c841b2
files
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/doc/v2_planning/API_coding_style.txt	Mon Aug 22 11:28:48 2011 -0400
+++ b/doc/v2_planning/API_coding_style.txt	Thu Sep 01 13:35:15 2011 -0400
@@ -277,6 +277,23 @@
         n_samples_per_split = n_samples / n_splits
         mean_x = sum(x) / len(x)
 
+    * If you really have to catch all exceptions, in general you should use
+      ``except Exception:`` rather than ``except:``, as the latter also catches
+      interrupts like when hitting Ctrl-C.
+
+      .. code-block:: python
+
+        # Good (assuming you *must* be catching all exceptions).
+        try:
+            someting_that_may_fail_in_unexpected_ways()
+        except Exception:
+            do_something_if_it_failed()
+        # Bad.
+        try:
+            someting_that_may_fail_in_unexpected_ways()
+        except:
+            do_something_if_it_failed()
+
     * Use either ``try ... except`` or ``try ... finally``, but do not mix
       ``except`` with ``finally`` (which is not supported in Python 2.4).
       You can however embed one into the other to mimic the ``try ... except ...
@@ -287,14 +304,14 @@
         # Good.
         try:
             try:
-                something_that_may_fail()
+                something_that_may_fail_with_some_known_error()
             except SomeError:
                 do_something_if_it_failed()
         finally:
             always_do_this_regardless_of_what_happened()
         # Bad.
         try:
-            something_that_may_fail()
+            something_that_may_fail_with_some_known_error()
         except SomeError:
             do_something_if_it_failed()
         finally: