Help req: Problems with MySQLdb
rogue_pedro at yahoo.com
Fri Jun 23 12:05:54 EDT 2006
Bruno Desthuilliers wrote:
> Simon Forman wrote:
> > rodmc wrote:
> > except:
> > print "A database connection error has occurred"
> How can you assert it is a database connection error ?
assert "database connection" in error
I was really just leaving as much of the OP's code unchanged as seemed
useful. Maybe they *want* to print that (possibly inaccurate) message
and return False (from what appears to be module-level code at that!)
FWIW, if I wanted the code to keep going but still report the exception
I would use the logging module's exception() method. But that seemed a
lot to explain.
> > traceback.print_exc()
> > return False
> > else:
> > pass
> > #The rest of the program
> You get the same result - with a more accurate error message - by not
> handling the exception at all.
You'd get the same traceback printed out either way, but the generic
except statement with the possibly inaccurate message does seem naive
to me. However, it's entirely possible that the OP *would* like the
code to keep running despite any exceptions while trying to connect to
the db. In that case, using traceback (or logging) is (IMHO) a
reasonable way to do that but still find out what went wrong.
More information about the Python-list