summaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/python/bindings/py_errors.h
blob: 1aa6ecf6eb0a5bba80d451a1201b0137f036e7ad (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
#pragma once

#include <util/generic/fwd.h>

namespace NPython {

TString GetLastErrorAsString();

#define PY_TRY try

#define PY_CATCH(ErrorValue)                           \
    catch (const yexception& e) {                      \
        PyErr_SetString(PyExc_RuntimeError, e.what()); \
        return ErrorValue;                             \
    }

#define PY_ENSURE(condition, message)      \
    do {                                   \
        if (Y_UNLIKELY(!(condition))) {    \
            throw yexception() << message; \
        }                                  \
    } while (0)

} // namespace NPython