C++ YT Wrapper
C++ library for working with YT clusters
Loading...
Searching...
No Matches
finish_or_die.h
1#pragma once
2
3#include <util/system/yassert.h>
4
5#include <exception>
6
8namespace NYT::NDetail {
9
11
12template <typename T>
13void FinishOrDie(T* pThis, bool autoFinish, const char* className) noexcept
14{
15 if (!autoFinish) {
16 return;
17 }
18
19 auto fail = [&] (const char* what) {
20 Y_ABORT(
21 "\n\n"
22 "Destructor of %s caught exception during Finish: %s.\n"
23 "Some data is probably has not been written.\n"
24 "In order to handle such exceptions consider explicitly call Finish() method.\n",
25 className,
26 what);
27 };
28
29 try {
30 pThis->Finish();
31 } catch (const std::exception& ex) {
32 if (!std::uncaught_exceptions()) {
33 fail(ex.what());
34 }
35 } catch (...) {
36 if (!std::uncaught_exceptions()) {
37 fail("<unknown exception>");
38 }
39 }
40}
41
43
44} // namespace NYT::NDetail