I have a database access module that I call with a query or command. He determines what to do with the database, and tries to do it. But, for example, if the request or command line is pathological, a call to the PGDB base module may throw an exception.
Some incredibly useful information is returned by PGDB (from PostgreSQL at the same time), in particular, causing what errors were found in the query or command. This use of the various PGDB functions extracts this information:
try: pgdb.dothing(mod.withx) except Exception, e: mod.error = 'pgdb.dothing('+str(type(mod.withx))+str(mod.withx)+') failed with: '+str(e)
Then, when the class returns, fails, the object contains a message in .error and viola, I can fix my stupidity in the request or command.
And all this works very well - (in Python 2.2.2, which may someday change to 2.higher ... but not now - and never, never 3. independently)
But ... I found this opacity bit: "the exception should not be inherited from Exception. So plain" except: "catches all exceptions, not just the system. String exceptions is one example of an exception that does not inherit from Exception "
So, the question is: Why does it bother me? If an exception occurs, I want to know why. I don't care where it came from, I just want an error message, and I'm sure Python doesn't want to stop. This will include if the error came from a string thing or something else. Therefore, in addition to catching everything is good. Or it should be.
Does this mean that the Exception parameter means that I will not catch the error if it comes from, for example, internal String strings? And then what, the code will stop with an uncaught exception? And then I need a series of catches for each type that "does not inherit from exception" to get the behavior I want? Something like that:
try: pgdb.dothing(mod.withx) except Exception, e: mod.error = 'pgdb.dothing('+str(type(mod.withx))+str(mod.withx)+') failed with: '+str(e) except: mod.error = 'pgdb.dothing('+str(type(mod.withx))+str(mod.withx)+') failed with: WTF???'
... because it really ... kind of sucks.
And if so, is there another way I can catch all exceptions of all types and get an error message for them? It seems like this would be very high, very desirable (and it also looks like a single liner should solve it, and it should look like a previous example, not the last).
Please answer before: Yes, I know Python 2.2.2 is deprecated. No, it will not be updated soon. It is a production system with several million lines of code; it is stable, and we want it to stay that way, based on "not broken, not fixing."
I just need a solid understanding of this part of the exclusion process that Iโve been beaten up. All the explanations seem to make assumptions about what I know, which are ... optimistic. :)
Thank you for understanding.