PL/pgSQL function – Catch errors

You can use EXCEPTION WHEN OTHERS clause:

BEGIN
  do something
EXCEPTION WHEN OTHERS THEN
  handle any exception
END;

Without some exception a using of this clause is not good idea. The debugging, issue diagnostics can be terrible when you use this pattern. It is strong feature (sometimes necessary), but dangerous!

Attention – the entry to, end leave of protected section has significant load. The overhead of savepoint and releasing of savepoint is not small. The overhead of this construct is significantly higher than on Oracle (although there is visual similarity, it does different things). Although this code looks like code in PL/SQL, the implementation is absolutely different. If you expect higher load of your application, use it carefully (not inside cycles, …)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)