How do I use exception handling ?

Asked by mady

I did not find any example how I use exception handling.

Could you please tell me how can I use it corrctly.

I use now the exceeption as follows.

import PySQLPool

connection = PySQLPool.getNewConnection(username='root', password='123456', host='localhost', db='mydb')
query = PySQLPool.getNewQuery(connection)
query.Query('select * from table')
for row in query.record:
    print row['column']


Question information

English Edit question
PySQLPool Edit question
Nikoleta Verbeck Edit question
Last query:
Last reply:
Revision history for this message
Nikoleta Verbeck (nerdynick) said :

So the way you are wrapping your Try/Except is correct except the type of exception you will be getting are not of type Exception. They will be of type MySQLdb.Error as PySQLPool currently doesn't wrap any of the exceptions thrown up from the MySQLdb layer. It only captures them temporally to make sure we close out everything and do some other finalizations before passing them back up the stack again.

Revision history for this message
Nikoleta Verbeck (nerdynick) said :

Just opened a FAQ for this question as I see it possible coming up from a few others as time goes on.

Nick Verbeck suggests this article as an answer to your question:
FAQ #905: “How do I handle exceptions?”.

Can you help with this problem?

Provide an answer of your own, or ask mady for more information if necessary.

To post a message you must log in.