Exception handling for mysql