Re: Catch exceptions outside function

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Catch exceptions outside function
Дата
Msg-id 1379510613320-5771426.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: Catch exceptions outside function  (Roberto Grandi <roberto.grandi@trovaprezzi.it>)
Ответы Re: Catch exceptions outside function
Список pgsql-admin
Roberto Grandi wrote
> Hi
>
> this is my script in details, remember that I launch it by .Net code
> (devart connector):
>
>
> SET LOCAL statement_timeout TO 1000;
> BEGIN;
>
> SELECT pg_sleep(5); -- QUERY that is long running;
>
> -- Some exception catch such as EXCEPTION
>
> END;
>
>
> I supposed my code can throw an eception for timeout and I would catch it.
> Otherwise consecutives queries report "Transaction is aborted message
> error".
>
> Do you have any suggestion for me?

Set your timeout longer than 5 seconds or sleep less than one second.

You cannot catch an exception directly in the top-level SQL language portion
of a command environment.  If an exception gets that far your transaction
has failed and you have to ROLLBACK.

You can use savepoints to limit how far you have to rollback - see the
documentation.

Exceptions should not occur (or do so rarely) and so they cannot be simply
ignored.  If you have code that you expect to throw an exception you should
try to rewrite it to test first and return true/false for availability.  not
always possible so catch and savepoints are ther to do if you must.

David J.

P.S. version 8.3 is no loner supported.
P.P.S please follow list convention and bottom or interleave post.





--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Catch-exceptions-outside-function-tp5771398p5771426.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.


В списке pgsql-admin по дате отправления:

Предыдущее
От: Albe Laurenz
Дата:
Сообщение: Re: Catch exceptions outside function
Следующее
От: Scott Ribe
Дата:
Сообщение: Re: Catch exceptions outside function