Exception Messages
Wanderer
wanderer at dialup4less.com
Mon Oct 15 13:18:51 EDT 2012
On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:
>
> Yes, but you've put the message in msg, and Exception doesn't have that
>
> attribute.
>
That's weird. I got this Exception class definition idea from this post by Guido van Rostrum, Where he gives this main function to look like
import sys
import getopt
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv=None):
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error, msg:
raise Usage(msg)
# more code, unchanged
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2
if __name__ == "__main__":
sys.exit(main())
http://www.artima.com/weblogs/viewpost.jsp?thread=4829
More information about the Python-list
mailing list