I know that the MySQL errors are split into client and server types. Has anyone discerned any further structure in the numbering?
I love applications that hide errors from the user and try to recover and continue execution, so am trying to switch from printing a string like “Doh! Connection failed.” to a custom class of database exceptions and a single handler to catch all database connection errors that aren’t caught within the function that threw them or get rethrown. I figure I can try to recover right there and re-throw if that fails. I thought I might try using a different catch block for different types of errors like connection failures, memory errors, prepared procedure errors, etc., When I tried to figure out a test for connection errors to start with, there seem to be several clusters that may relate, however I’m not sure if some of them are connection errors or not! For example: Error 2048: (CR_INVALID_CONN_HANDLE) Invalid connection handle.( When would this occur?!?)
Some of the errors listed at briandunning.com/error-codes/?source=MySQL have a SQLSTATE code. what are these?
I am hoping I can test for a range or ranges using the existing codes.
Has anyone else tried to do this? is there a PEAR package? How about a good book?
If they aren’t following a logical pattern would I be better off rolling my own custom codes? Is there a better approach I don’t see? This is my first time with exceptions, so I may be going about this all wrong. Thanks!
From the MySQL manual:
This page and its subpages should tell you all you need to know:
http://dev.mysql.com/doc/refman/5.0/en/error-handling.html
And here’s a list of SQLSTATE errors from IBM that goes into the structure behind the 5 character error code: http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls520.htm
A quote: