[ovs-dev] [python 18/31] ovs.db.types: Simplify code to avoid try/except case.

Ben Pfaff blp at nicira.com
Tue Aug 23 21:05:12 UTC 2011


Also fixes a typo that caused one version of the error message to have a
hyphen and the other to have a space.

Suggested-by: Reid Price <reid at nicira.com>
---
 python/ovs/db/types.py |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py
index f7bc248..416d745 100644
--- a/python/ovs/db/types.py
+++ b/python/ovs/db/types.py
@@ -30,16 +30,14 @@ class AtomicType(object):
             for atomic_type in ATOMIC_TYPES:
                 if s == atomic_type.name:
                     return atomic_type
-        raise error.Error('"%s" is not an atomic type' % s)
+        raise error.Error('"%s" is not an atomic-type' % s, s)
 
     @staticmethod
     def from_json(json):
         if type(json) not in [str, unicode]:
             raise error.Error("atomic-type expected", json)
-        try:
+        else:
             return AtomicType.from_string(json)
-        except error.Error:
-            raise error.Error('"%s" is not an atomic-type' % json, json)
 
     def __str__(self):
         return self.name
-- 
1.7.4.4




More information about the dev mailing list