aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/noexcept_scope.h
blob: bdd7a98925a6c9d9096c46502c931eef58e7065e (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
#pragma once
#include <Common/Exception.h>
#include <Common/LockMemoryExceptionInThread.h>

/// It can be used in critical places to exit on unexpected exceptions.
/// SIGABRT is usually better that broken in-memory state with unpredictable consequences.
/// It also temporarily disables exception from memory tracker in current thread.
/// Strict version does not take into account nested exception (i.e. it aborts even when we're in catch block).

#define NOEXCEPT_SCOPE_IMPL(...) do {                          \
    LockMemoryExceptionInThread                                \
        noexcept_lock_memory_tracker(VariableContext::Global); \
    try                                                        \
    {                                                          \
        __VA_ARGS__;                                           \
    }                                                          \
    catch (...)                                                \
    {                                                          \
        DB::tryLogCurrentException(__PRETTY_FUNCTION__);       \
        std::terminate();                                      \
    }                                                          \
} while (0) /* to allow leading semi-colon */

#define NOEXCEPT_SCOPE_STRICT(...)                    \
    if (std::uncaught_exceptions()) std::terminate(); \
    NOEXCEPT_SCOPE_IMPL(__VA_ARGS__)

#define NOEXCEPT_SCOPE(...) NOEXCEPT_SCOPE_IMPL(__VA_ARGS__)