errorhandler.cxx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** Implementation of pqxx::errorhandler and helpers.
  2. *
  3. * pqxx::errorhandler allows programs to receive errors and warnings.
  4. *
  5. * Copyright (c) 2000-2022, Jeroen T. Vermeulen.
  6. *
  7. * See COPYING for copyright license. If you did not receive a file called
  8. * COPYING with this source code, please notify the distributor of this
  9. * mistake, or contact the author.
  10. */
  11. #include "pqxx-source.hxx"
  12. #include "pqxx/internal/header-pre.hxx"
  13. #include "pqxx/connection.hxx"
  14. #include "pqxx/errorhandler.hxx"
  15. #include "pqxx/internal/gates/connection-errorhandler.hxx"
  16. #include "pqxx/internal/header-post.hxx"
  17. pqxx::errorhandler::errorhandler(connection &conn) : m_home{&conn}
  18. {
  19. pqxx::internal::gate::connection_errorhandler{*m_home}.register_errorhandler(
  20. this);
  21. }
  22. pqxx::errorhandler::~errorhandler()
  23. {
  24. unregister();
  25. }
  26. void pqxx::errorhandler::unregister() noexcept
  27. {
  28. if (m_home != nullptr)
  29. {
  30. pqxx::internal::gate::connection_errorhandler connection_gate{*m_home};
  31. m_home = nullptr;
  32. connection_gate.unregister_errorhandler(this);
  33. }
  34. }