I am editing the question for clarity.
I created a class in a module that imports MySQLdb. I have found that MySQLdb will raise an Exception if the table the user passes to my class does not exist. I am catching that exception, and passing a new one to the client. But even if the client catches my exception, the program still terminates. I have also tried passing to the client the same Exception MySQLdb is giving my class.
Since the client will be calling my method in a loop, passing in various table names, I don't want the program to choke if the table name is bad. I'd like the client's iterations to continue to the next valid table name. Here is a snippet (tableName is an arg pass in to the method):
In my class/module:
self.tableName = tableName
try:
self.cursor.execute("select * from " + self.tableName + ";") #Will raise Exception if the table does not exist.
except:
raise MyException("\n*** " + self.tableName + " does not exist. ***")
In the client:
tables = ["BadTableName", "GoodTableNameA", "GoodTableNameB","GoodTableNameC"]
try:
for table in tables:
my_method(table) #Exception message gets passed in with BadTableName, but the program ends. Subsequest iterations of this loop never happen
except Exception, e:
print e
I would like the client to continue even after calling my_method(BadTableName).
By the way, my_method() is part of a class defined in its own module which the client is importing.
Thank you.
MyExceptioninherit fromException, or something else? Which version of Python are you on?