Move getLastInsertId inside try {} block