Vincenzo Romano <vincenzo.romano@notorand.it> writes:
> The weirdness is that it doesn't produce any notice the first two times.
> At the third invocation I see the notice coming out.
I'd suggest tweaking the exception handler to print the error it caught;
that would probably clarify what is happening.
regards, tom lane