raise errors
Ulrich Eckhardt
eckhardt at satorlaser.com
Mon Sep 21 06:22:43 EDT 2009
daved170 wrote:
> I need help with exceptions raising.
> My goal is to print at the outer functions all the errors including
> the most inner one.
>
> For example:
>
> def foo1(self):
> try:
> foo2()
> except ? :
> print "outer Err at foo1" + ??
>
> def foo2(self):
> try:
> error occured
> except ? :
> raise "inner Err at foo2"
>
>
> the ? remarks that I have no idea what to use.
>
> I would like the print to be : outer Err at foo1 , inner Err at foo1
Take a look at the builtin debugger facility, i.e. 'import pdb'. There, you
have a traceback module which might already give you what you want.
One more advise though: Do not catch exceptions you don't handle! Make sure
they can pass through your code without hurting anything and then catch and
log them in a place where you actually can handle them. In particular,
don't wrap each and every tiny morsel of code into try/except handlers as
you would (have to) do if you were using return values.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list