try exec

Ype Kingma ykingma at accessforall.nl
Fri Jan 17 19:51:32 CET 2003


Afanasiy wrote:

> On Thu, 16 Jan 2003 22:28:05 +0100, Ype Kingma <ykingma at accessforall.nl>
> wrote:
> 
>>Afanasiy wrote:
>>
>>> Some code I "exec" throws a TypeError exception. I want it to throw this
>>> exception but want to be able to catch this along with the others which
>>> are in fact being caught by the try/except block.
>>> 
>>> The specific TypeError in this case is caused by a module-defined
>>> function being called with the incorrect number of arguments. Again,
>>> I want to catch this exception. The problem is, this exception, unlike
>>> the others, is not being caught/handled by my try/except block.
>>
>>How do you know it is thrown?
> 
> Upon execution of the Python script, the standard exception printout
> occurs at this location, denoting exactly what the error is and
> halting execution of the script.
> 
>   Traceback (most recent call last):
>     File "C:\test.py", line 21, in ?
>       for line, expecting in lines:
>   TypeError: function takes exactly 0 arguments (1 given)
> 
> Where, given my code it should have shown (and continued execution) :

I don't follow this '(and continued execution)'.
 
>   ('Foo() takes exactly 0 arguments (1 given)',)
> 

But the lines read (from your first post):

lines = [
  ('foo = MyModule.Something()',1),
  ('foo.Function("hmm")',0),
  ...etc..
]

Where is this Foo() call?

Could you isolate the problem in some minimal bits of code
and post all that code?

Regards,
Ype


-- 
email at xs4all.nl




More information about the Python-list mailing list