aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/finish_or_die.h
blob: cb8d96c454e3ea12800da1a9aae11ad4c0d7e8da (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
#pragma once

#include <util/system/yassert.h>

#include <exception>

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

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

template <typename T>
void FinishOrDie(T* pThis, const char* className) noexcept
{
    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