Menu

exceptions

Help
2002-03-01
2012-09-19
  • Egon Frerich

    Egon Frerich - 2002-03-01

    How can I use error messages from the MySQL database in a Python program?

    Regards,

    Egon Frerich

     
    • Marco Wesselgren

      The MySQLdb has a args tuple from .Error , you could use it like this:

      try:

          myconnection = MySQLdb.connect (   
                  <args for the connection setup >

      except MySQLdb.Error , <somevariable>:
          print "Error %d %s " % (somevariable.args[0] , somevariable.args[1])
      sys.exit() (or what you want to do if an error occurs)

      the first [0] contains an errorcode the second one [1] a string describing the error.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.