Handle MySQL exceptions