aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/finish_or_die.h
blob: a6e190328f781edf0bdc681e868892e7351c8f69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include <util/system/yassert.h>

#include <exception>

/// @cond Doxygen_Suppress
namespace NYT::NDetail {

////////////////////////////////////////////////////////////////////////////////

template <typename T>
void FinishOrDie(T* pThis, bool autoFinish, const char* className) noexcept
{
    if (!autoFinish) {
        return;
    }

    auto fail = [&] (const char* what) {
        Y_ABORT(
            "\n\n"
            "Destructor of %s caught exception during Finish: %s.\n"
            "Some data is probably has not been written.\n"
            "In order to handle such exceptions consider explicitly call Finish() method.\n",
            className,
            what);
    };

    try {
        pThis->Finish();
    } catch (const std::exception& ex) {
        if (!std::uncaught_exceptions()) {
            fail(ex.what());
        }
    } catch (...) {
        if (!std::uncaught_exceptions()) {
            fail("<unknown exception>");
        }
    }
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NDetail
/// @endcond