Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31331
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-10-15 10:44 -0700 |
| References | (1 earlier) <mailman.2217.1350317845.27098.python-list@python.org> <k5hd7c$emf$1@reader1.panix.com> <mailman.2218.1350318893.27098.python-list@python.org> <96889d3a-1217-4743-93b5-f8dd5686eebd@googlegroups.com> <mailman.2226.1350322455.27098.python-list@python.org> |
| Subject | Re: Exception Messages |
| From | Wanderer <wanderer@dialup4less.com> |
| Message-ID | <mailman.2227.1350323056.27098.python-list@python.org> (permalink) |
On Monday, October 15, 2012 1:34:24 PM UTC-4, MRAB wrote: > On 2012-10-15 18:18, Wanderer wrote: > > > 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 > > > > > > > > Note how it explicitly prints err.msg. Not in the raise statement. Adding the def __str__ made it work for me. Thanks
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 09:00 -0700
Re: Exception Messages MRAB <python@mrabarnett.plus.com> - 2012-10-15 17:17 +0100
Re: Exception Messages John Gordon <gordon@panix.com> - 2012-10-15 16:22 +0000
Re: Exception Messages MRAB <python@mrabarnett.plus.com> - 2012-10-15 17:34 +0100
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:18 -0700
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:20 -0700
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:20 -0700
Re: Exception Messages MRAB <python@mrabarnett.plus.com> - 2012-10-15 18:34 +0100
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:44 -0700
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:44 -0700
Re: Exception Messages Wanderer <wanderer@dialup4less.com> - 2012-10-15 10:18 -0700
Re: Exception Messages Dave Angel <d@davea.name> - 2012-10-15 12:42 -0400
Re: Exception Messages Terry Reedy <tjreedy@udel.edu> - 2012-10-15 15:15 -0400
Re: Exception Messages Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-16 00:47 +0000
csiph-web