Client 2—Adding Error Checking
As mentioned earlier, libpqxx follows the STL philosophy that an error condition should be reported by throwing an exception. libpqxx defines three exception types, all derived from std::runtime_error:
sql_error— Thrown when the PostgreSQL server reports an error
broken_connection— Thrown when the libpqxx library detects that the connection to the server has been broken
in_doubt_error— Thrown when you COMMIT a transaction but the connection to the server fails before libpqxx has received an acknowledgement that the COMMIT completed
Because these exception classes are ultimately derived from std::exception, each provides a member function named what() that returns a description of the error that occurred. In addition, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access