Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wiki] Wrong example about working with exceptions #48

Closed
01e9 opened this issue Dec 26, 2017 · 1 comment
Closed

[Wiki] Wrong example about working with exceptions #48

01e9 opened this issue Dec 26, 2017 · 1 comment

Comments

@01e9
Copy link
Contributor

01e9 commented Dec 26, 2017

http://pqxx.org/development/libpqxx/wiki/WikiStart#Handlingerrors

#include <iostream>
#include <pqxx/except>
#include "my-db-code.hxx"

int main(int argc, char *argv[])
{
  try
  {
    do_db_work(trans);
  }
  catch (const std::exception &e)
  {
    std::cerr << e.what() << std::endl;
    return 1;
  }
  catch (const pqxx::sql_error &e)
  {
    std::cerr
        << "Database error: " << e.what() << std::endl
        << "Query was: " << e.query() << std::endl;
    return 2;
  }
}

The second catch of pqxx::sql_error will never execute https://ideone.com/Nsf3SM
It must be moved before std::exception catch https://ideone.com/JCUWu8

@jtv
Copy link
Owner

jtv commented Dec 26, 2017

Whoops! You're right, of course. I've made the change.

@jtv jtv closed this as completed Dec 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants