Object type check

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Feb 7 16:40:42 EST 2007


king kikapu a écrit :
> at first, thanks you all for your help!
> 
> So, i will follow your advice.In a moment though, i thought that "ok,
> do not check anything of the parameter's type but do a try/catch at
> the calls inside the function"

And so what ? Once an exception got caught, what are you going to do ?
Raise another exception ? Re-raise the same exception ? In both cases, you
usually don't gain much - and sometimes loose (time, simplicity, 
readability, and
a usefull traceback).

Unless you know how to handle it, it's usually better to let the exception
propagate. Usually, the person coding the *application* (ie: the coder using
your lib) will wrap the whole thing into a catch-all exception handler 
at the higher level,
so he can log the full traceback, display a nice error to the end user, 
and crash gracefully.
As a library programmer, you should not care about this.

> But this way, i would rather defeat the purpose because i have to try/
> catch in *every* call inside the func.
> So, i suppose that i wouldn't want to do that and just try to make the
> call in whatever they passed me in.

You're starting to see the light, my friend !-)

> Strange world the dynamic one....

If that's too dynamic for you, then run for your life - this is just the 
visible
part of the iceberg.



More information about the Python-list mailing list