[MERGE] Good python practice: specify which exception to catch.
Enrico Zini
enrico at enricozini.org
Fri Dec 28 02:26:21 UTC 2007
On Thu, Dec 27, 2007 at 06:09:03PM +0100, Adeodato Simó wrote:
> try:
> maint_RE = re.compile(sys.argv[1])
> -except:
> +except IndexError:
> print "Usage: grep-maintainer REGEXP"
> sys.exit(1)
+1. You may however want to also catch "sre_constants.error" (what a
stupid exception name is that?) to show nice error messages in case of
malformed regexps. Oh, and print errors to sys.stderr:
try:
maint_RE = re.compile(sys.argv[1])
except IndexError:
print >>sys.stderr, "Usage: grep-maintainer REGEXP"
sys.exit(1)
except sre_constants.error, e:
print >>sys.stderr, "Error in the regexp:", e
sys.exit(1)
Ciao,
Enrico
--
GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <enrico at debian.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/pkg-python-debian-discuss/attachments/20071228/9e235e09/attachment.pgp
More information about the pkg-python-debian-discuss
mailing list