Error handling expectations

Started by James Colemanover 7 years ago3 messageshackers
Jump to latest
#1James Coleman
jtc331@gmail.com

I'm working on adding a tuple_data_record function to pageinspect to
parallel tuple_data_split (returning the record type of the relation being
examined rather than an array of attributes as on-disk byte data).

This my first real foray into the Postgres codebase, so an beginner
question: I noticed that existing C functions in pageinspect often do error
checking and then report the error with ereport but still continue on to
execute the rest of the function instead of early returning. Is this
standard practice? Or should I be reporting the error and then cleaning up
and returning rather than continuing to execute?

Thanks,
James Coleman

#2Andres Freund
andres@anarazel.de
In reply to: James Coleman (#1)
Re: Error handling expectations

Hi,

On 2018-10-15 13:21:04 -0400, James Coleman wrote:

This my first real foray into the Postgres codebase, so an beginner
question: I noticed that existing C functions in pageinspect often do error
checking and then report the error with ereport but still continue on to
execute the rest of the function instead of early returning. Is this
standard practice? Or should I be reporting the error and then cleaning up
and returning rather than continuing to execute?

ereport basically throws an exception when elevel >= ERROR. I suggest
looking at elog.h's comments above elog and PG_TRY().

Greetings,

Andres Freund

#3James Coleman
jtc331@gmail.com
In reply to: Andres Freund (#2)
Re: Error handling expectations

Perfect. Thanks for the pointer, Andres, that's exactly what I was looking
for.

On Mon, Oct 15, 2018 at 1:28 PM Andres Freund <andres@anarazel.de> wrote:

Show quoted text

Hi,

On 2018-10-15 13:21:04 -0400, James Coleman wrote:

This my first real foray into the Postgres codebase, so an beginner
question: I noticed that existing C functions in pageinspect often do

error

checking and then report the error with ereport but still continue on to
execute the rest of the function instead of early returning. Is this
standard practice? Or should I be reporting the error and then cleaning

up

and returning rather than continuing to execute?

ereport basically throws an exception when elevel >= ERROR. I suggest
looking at elog.h's comments above elog and PG_TRY().

Greetings,

Andres Freund