newb: Creating Exception
Dustan
DustanGroups at gmail.com
Wed Dec 13 06:45:31 EST 2006
johnny wrote:
> 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.
You might want to get a book on python, rather than depend on the
documentation, which is, as you say, written for more experienced
programmers.
http://wiki.python.org/moin/IntroductoryBooks
I started with a book, and reading the tutorial now, am quite glad I
did. One thing that did bug me, at least briefly, is sometimes beginner
books don't explain what a line of code is actually doing - not
necessarily how it works, but as much information as is necessary to
actually be able to use the code shown.
> Dennis Lee Bieber wrote:
> > On 11 Dec 2006 16:02:02 -0800, "johnny" <rampeters at gmail.com> 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
> > wlfraed at ix.netcom.com wulfraed at bestiaria.com
> > HTTP://wlfraed.home.netcom.com/
> > (Bestiaria Support Staff: web-asst at bestiaria.com)
> > HTTP://www.bestiaria.com/
More information about the Python-list
mailing list