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, ...
Get PostgreSQL, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.