Rev 5571: (mbp) developer guidelines about exception classes (Martin Pool) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Dec 16 06:57:23 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5571 [merge]
revision-id: pqm at pqm.ubuntu.com-20101216065722-omb8r4sg7eps6mry
parent: pqm at pqm.ubuntu.com-20101215012832-s7gz2rnm1n94f4eu
parent: mbp at sourcefrog.net-20101214233941-95uq6n9xf0xgtyc3
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-12-16 06:57:22 +0000
message:
  (mbp) developer guidelines about exception classes (Martin Pool)
modified:
  doc/developers/code-style.txt  codestyle.txt-20100515105711-133ealf7ereiq2eq-1
=== modified file 'doc/developers/code-style.txt'
--- a/doc/developers/code-style.txt	2010-09-28 07:20:09 +0000
+++ b/doc/developers/code-style.txt	2010-12-14 23:39:41 +0000
@@ -364,6 +364,8 @@
 
 Because repr methods are often called when something has already gone
 wrong, they should be written somewhat more defensively than most code.
+They shouldn't have side effects like doing network or disk
+IO.
 The object may be half-initialized or in some other way in an illegal
 state.  The repr method shouldn't raise an exception, or it may hide the
 (probably more useful) underlying exception.
@@ -385,6 +387,13 @@
 ``Exception`` (which excludes system errors in Python2.5 and later) would
 be better.
 
+The ``__str__`` method on exceptions should be small and have no side
+effects, following the rules given for `Object string representations`_.
+In particular it should not do any network IO, or complicated
+introspection of other objects.  All the state needed to present the
+exception to the user should be gathered before the error is raised.
+In other words, exceptions should basically be value objects.
+
 
 Test coverage
 =============




More information about the bazaar-commits mailing list