Checking function calls
__peter__ at web.de
Wed Mar 8 21:44:23 CET 2006
Fredrik Tolf wrote:
> # ...
> if callable(f):
> except TypeError:
> self.reply("err", "argno")
> # ...
> However, this results in bugs in the server code that would cause
> TypeError to reply to the client that it had the wrong number of args,
> and I can't see what the real cause is without turning off that check
> while debugging. Therefore, I'd like to check in advance whether cv[1:]
> would raise a TypeError upon calling f with it or not. And of course,
> I'd like to be able to use cmd_* functions with variable arglists as
If you must, just check the error message, not just the type of exception.
I'd just drop the cryptical error codes like 'argno' and 'unk' and pass on
the actual error message:
tp, exc, traceback = sys.exc_info()
Note that the check whether f is callable is also gone.
More information about the Python-list