Thank you Dennis,
So when line 2, gets executed, its exception goes to do_some1_error.
And when line 3, gets executed, its exception goes to do_some2_error
and so on.

line 1:  try
line 2:    do_some1
line 3:    do_some2
line 4:    do_some3
line 5: except do_some1_error:
line 6:            whatever1
line 7: except do_some2_error:
line 8:            whatever2
line 9: except do_some3_error:
line 10:            whatever3

Documentation is not written for newbs, it's written by guys with 6yrs
of experience FOR guys with 6yrs of experience.

Dennis Lee Bieber wrote:
> On 11 Dec 2006 16:02:02 -0800, "johnny" <[EMAIL PROTECTED]> declaimed
> the following in gmane.comp.python.general:
>
> > I want to print individual exception for database connection, sql
> > execution, database closing, closing the cursor.  Can I do it with one
> > try..catch or I need a nested try...catch?
>
>       Python does not have a "catch" instruction.
>
>       You could do:
>
>       try:
>               make connection #though that should, in my mind, be done
>                                                       #as part of the 
> initialization of the thread
>                                                       #and not as part of any 
> processing loop
>               make cursor
>               execute sql
>               fetch results if any
>               close cursor
>               commit transaction
>               close connection        #which I'd make part of the termination
>                                                       #of the thread
>       except Exception1, msg:
>               do something
>       except Exception2, msg:
>               do something2
>       ...
>
> IF each step raises a different exception type -- if all the database
> returns is "DatabaseError", then there is nothing to separate them by.
> Also note that if an exception happens in the "execute sql" stage, your
> handler may need to do a rollback, and the closes.
>
> --
>       Wulfraed        Dennis Lee Bieber               KD6MOG
>       [EMAIL PROTECTED]               [EMAIL PROTECTED]
>               HTTP://wlfraed.home.netcom.com/
>       (Bestiaria Support Staff:               [EMAIL PROTECTED])
>               HTTP://www.bestiaria.com/

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to