finish_or_die.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <util/system/yassert.h>
  3. #include <exception>
  4. /// @cond Doxygen_Suppress
  5. namespace NYT::NDetail {
  6. ////////////////////////////////////////////////////////////////////////////////
  7. template <typename T>
  8. void FinishOrDie(T* pThis, const char* className) noexcept
  9. {
  10. auto fail = [&] (const char* what) {
  11. Y_ABORT(
  12. "\n\n"
  13. "Destructor of %s caught exception during Finish: %s.\n"
  14. "Some data is probably has not been written.\n"
  15. "In order to handle such exceptions consider explicitly call Finish() method.\n",
  16. className,
  17. what);
  18. };
  19. try {
  20. pThis->Finish();
  21. } catch (const std::exception& ex) {
  22. if (!std::uncaught_exceptions()) {
  23. fail(ex.what());
  24. }
  25. } catch (...) {
  26. if (!std::uncaught_exceptions()) {
  27. fail("<unknown exception>");
  28. }
  29. }
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////
  32. } // namespace NYT::NDetail
  33. /// @endcond