Trigve Siver
2010-12-15 13:50:23 UTC
Hi,
I have some idea about non-throwing functions in pqxx. And want to know some
opinions.
As stated in [1] not all errors should/shall be treated as exceptional
behaviour. So I was thinking if it also applies for SQL. There are some types of
errors which are exceptional and the flow of the program could diverge. For
instance syntax error of SQL query is an exception behaviour and exception
should be raised (But I could ale imagine that for some query verifier app it
isn't). On the other side there could be SQL error about primary key duplicate
when inserting some records. This error could not be exceptional if we are
awaiting it. This situation could be solved for instance with checking if record
exists; if yes then show some error message, if not then insert record. Or we
could try to insert record and if record (with PK, UNIQUE, ...) already exist
show error message from the error code. Also we could wrap the code in the
try-catch block and try to catch desired exception. But it is expensive because
throwing/catching exceptions in C++ is expensive AFAIK (but for me biggest
problem is that this kind of error isn't exceptional one as stated above :)).
So I get this idea about adding overloads to some operations that will be
non-throwing (here I mean SQL non-throwing because some other C++ exceptions
could be thrown from somewhere deep in stack). I'm proposing for now adding
overload pqxx::transaction_base::exec(const std::stringstream &Query, error_code
&ec, const std::string &Desc=std::string()) as proof of concept. error_code
could be for now some simple struct with some error enums (this could be
detailed next). Of course I'm willing to implement it.
What do you think?
Thanks
Trigve
[1] -
http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html
I have some idea about non-throwing functions in pqxx. And want to know some
opinions.
As stated in [1] not all errors should/shall be treated as exceptional
behaviour. So I was thinking if it also applies for SQL. There are some types of
errors which are exceptional and the flow of the program could diverge. For
instance syntax error of SQL query is an exception behaviour and exception
should be raised (But I could ale imagine that for some query verifier app it
isn't). On the other side there could be SQL error about primary key duplicate
when inserting some records. This error could not be exceptional if we are
awaiting it. This situation could be solved for instance with checking if record
exists; if yes then show some error message, if not then insert record. Or we
could try to insert record and if record (with PK, UNIQUE, ...) already exist
show error message from the error code. Also we could wrap the code in the
try-catch block and try to catch desired exception. But it is expensive because
throwing/catching exceptions in C++ is expensive AFAIK (but for me biggest
problem is that this kind of error isn't exceptional one as stated above :)).
So I get this idea about adding overloads to some operations that will be
non-throwing (here I mean SQL non-throwing because some other C++ exceptions
could be thrown from somewhere deep in stack). I'm proposing for now adding
overload pqxx::transaction_base::exec(const std::stringstream &Query, error_code
&ec, const std::string &Desc=std::string()) as proof of concept. error_code
could be for now some simple struct with some error enums (this could be
detailed next). Of course I'm willing to implement it.
What do you think?
Thanks
Trigve
[1] -
http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html