Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24416
| Date | 2012-06-25 01:23 -0500 |
|---|---|
| From | Andrew Berg <bahamutzero8825@gmail.com> |
| Subject | Re: exception problem |
| References | <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <CAPTjJmqBz76smYiYweN2kbUb91RdGU=std2Z=jwiDkSpAPhR8g@mail.gmail.com> <4FE7F6CC.2050704@earthlink.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1477.1340605453.4697.python-list@python.org> (permalink) |
On 6/25/2012 12:27 AM, Charles Hixson wrote: > The documentation section covering the except statement could stand to > be a *LOT* clearer. I read the sections on the except statement and > exception handlers several times and couldn't figure out was the "as" > argument of the except statement was for. I agree that the tutorial doesn't explain the use of "as" very well, but it does cover that a bare except is not normally good to use: "The last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way!" > I still don't really know what > "as" means, except that if you use it, and you print out the "target", > you'll get some kind of informative message. "as" lets you refer to the exception object that was caught. I find this useful mainly for exceptions that have attributes (most built-in exceptions don't, but many user-defined exceptions do). A full traceback is much more useful for debugging than what a simple print(exc) will give. There are a few different ways to get traceback information without letting the exception simply propagate and terminate the program. You can get some simple information from sys.exc_info() (and you can feed the traceback object to a function in the traceback module), or you can log it with the logging.exception() function or the exception() method of a Logger from the same module. I recommend using logging. However, it's generally best to just let any unexpected exceptions propagate unless the program absolutely must continue, especially when debugging. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: exception problem Andrew Berg <bahamutzero8825@gmail.com> - 2012-06-25 01:23 -0500
csiph-web