handle exception in postgresql