aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/unwind_message.cpp
blob: 6a203eaf5331abef8a7a992c932e0a9e88d5a7f6 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "unwind_message.h"
#include <exception>

namespace vespalib {

UnwindMessage::UnwindMessage(const vespalib::string &msg)
    : _num_active(std::uncaught_exceptions()),
      _message(msg)
{
}

UnwindMessage::UnwindMessage(UnwindMessage &&rhs) noexcept
    : _num_active(std::uncaught_exceptions()),
      _message(rhs._message)
{
    rhs._message.clear();
}

UnwindMessage::~UnwindMessage() {
    if ((std::uncaught_exceptions() != _num_active) && !_message.empty()) {
        fprintf(stderr, "%s\n", _message.c_str());
    }
}

UnwindMessage unwind_msg(const char *fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    vespalib::string msg = make_string_va(fmt, ap);
    va_end(ap);
    return {msg};
}

} // namespace