Wrapping a Try: Except:

Joined
Dec 17, 2009
Messages
1
Reaction score
0
Though I am new to Python I've inherited some existing code that has existing functions that I'd like to be able to wrap with a try structure.

# The following type of code works but isn't in the desired format...
try:
old.function ( another_function_call() == True )
except
my.cleanup()

The format that is desired is as follows:
my.function ( another_Function_call() == True )

But the problem is that if the Function_call() throws an exception, the point at which the occurs is prior to the try. Even if the original test is wrapped e.g.

my.function ( self, expression )
try:
old.function ( expression )
except:
my.cleanup()


It appears that the function that is passed into the my.function as a part of the expression has the expression called/executed prior to the actual calling of my function code and thus the try is never reached. Is there a way around this one without having to re-write the original code or adding a try structure around the whole call?

Thanks for any guidance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top