Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Catching Exceptions.

Reply
Thread Tools

Catching Exceptions.

 
 
Keith Bolton
Guest
Posts: n/a
 
      09-27-2004
I am handling exceptions currently using try, except. Generally I don't
handle specific exceptions and am catching all.
Then if an exception occurs, I would like to capture that error string.
However, in the documentation it seems like
there is not a way to get the extra str data if you are handling all
exceptions and not specifically. Is there?

thanks

-keith
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      09-27-2004
Keith Bolton wrote:
> I am handling exceptions currently using try, except. Generally I don't
> handle specific exceptions and am catching all.
> Then if an exception occurs, I would like to capture that error string.
> However, in the documentation it seems like
> there is not a way to get the extra str data if you are handling all
> exceptions and not specifically. Is there?


Do generic "try/except" is a *very* bad idea, and almost never
either required, or hard to avoid.

Nevertheless, if you are doing it, you can basically just
do this to get the extra info:

try:
# failing code
except Exception, ex:
# use ex here just as you would have in a more specific handler
# such as with str(ex)

The key is that all exceptions are descendents of the class
Exception, except *deprecated* exceptions that are just
strings (as in "raise 'somefailure'"). (And those should never
be used in your own code anyway.)

-Peter
 
Reply With Quote
 
 
 
 
Fuzzyman
Guest
Posts: n/a
 
      09-27-2004
On Mon, 27 Sep 2004 08:44:52 -0700, "Keith Bolton"
<(E-Mail Removed)> wrote:

>I am handling exceptions currently using try, except. Generally I don't
>handle specific exceptions and am catching all.
>Then if an exception occurs, I would like to capture that error string.
> However, in the documentation it seems like
>there is not a way to get the extra str data if you are handling all
>exceptions and not specifically. Is there?
>
>thanks
>
>-keith


http://aspn.activestate.com/ASPN/Coo.../Recipe/259180

Above link is a simple recipe that will just extract the text of an
exception.

HTH

Regards,


Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html

 
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
How to catching loading exception? Bob ASP .Net 5 02-19-2005 07:07 AM
Catching Apache error with a Perl script PapaBear Perl 2 08-20-2003 12:56 PM
Catching events in web form fired by user control Nick Lewis ASP .Net 1 08-01-2003 12:01 PM
Re: catching exceptions from web user controls Marina ASP .Net 2 07-08-2003 04:48 PM
Catching an SelectedIndexChanged event from a DropDownList inside a DataGrid Dominic ASP .Net 2 07-04-2003 04:43 AM



Advertisments