python - Stop MySQLdb from crashing -


i'm using mysqldb connect database run queries. however, if password incorrect or mysqldb fails connect database, script stops running. instead, receive error message string, , continue script (as completion of queries not essential other parts of script). possible?

the script stops running because .connect() call raises exception.

you can catch exception try:, except: handler:

import mysqldb  try:     connection = mysqldb.connect(...) except mysqldb.error ex:     print "the connection failed: {}".format(ex) 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Socket.connect doesn't throw exception in Android -

SPSS keyboard combination alters encoding -