summaryrefslogtreecommitdiff
path: root/src/assert.cc
blob: b51815a58b7b6249b6d7eefe32ea966f1d1d8572 (plain)
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
#include "assert.hh"

#include "exception.hh"

#include <sys/types.h>
#include <unistd.h>

namespace Kakoune
{

struct assert_failed : logic_error
{
    assert_failed(const String& message)
        : m_message(message) {}

    const char* what() const override { return m_message.c_str(); }
private:
    String m_message;
};

void on_assert_failed(const char* message)
{
    String debug_info = "pid: " + to_string(getpid());
    int res = system(("xmessage -buttons 'quit:0,ignore:1' '"_str +
                      message + "\n[Debug Infos]\n" + debug_info + "'").c_str());
    switch (res)
    {
    case -1:
    case  0:
        throw assert_failed(message);
    case 1:
        return;
    }
}

}