Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: exception problem

Reply
Thread Tools

Re: exception problem

 
 
Andrew Berg
Guest
Posts: n/a
 
      06-25-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 3 06-26-2003 01:02 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 0 06-24-2003 12:46 PM



Advertisments