Postgres Function Exception Handling