How to trap exceptions inside PL/Perl functions?

From: "Dmitry Koterov" <dmitry(at)koterov(dot)ru>
To: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: How to trap exceptions inside PL/Perl functions?
Date: 2007-08-15 11:41:53
Message-ID: d7df81620708150441o7a4133ebl85cecf1b4b9d84fd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello.

In PL/PGSQL I could write:

BEGIN
SELECT * FROM non_existed_table;
EXCEPTION
WHEN ... THEN ...
END;

How to do it in PL/Perl? I tried the standard for Perl trapping method:

eval {
spi_exec_query("SELECT * FROM non_existed_table");
};
if ($@) { ... }

but it does not work - it says that "eval is not safe" or something like
that. But I use eval with {}, not with quotes, so - it has to be safe.
So, how to trap errors in this case?

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2007-08-15 12:04:36 Re: Best practice for: ERROR: invalid byte sequence for encoding "UTF8"
Previous Message Ivan Zolotukhin 2007-08-15 11:41:30 Best practice for: ERROR: invalid byte sequence for encoding "UTF8"