aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/require.cpp
blob: 9d45545871784a58ae78540d056f92abbf66299f (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "require.h"
#include <vespa/vespalib/stllike/asciistream.h>
#include <iostream>

namespace vespalib {

VESPA_IMPLEMENT_EXCEPTION(RequireFailedException, Exception);

void throw_require_failed(const char *description, const char *file, uint32_t line)
{
    asciistream msg;
    msg << "error: (" << description << ") failed";
    asciistream loc;
    loc << "file " << file << " line " << line;
    throw RequireFailedException(msg.c_str(), loc.c_str(), 2);
}

void handle_require_failure(const char *description, const char *file, uint32_t line)
{
    asciistream msg;
    std::cerr << file << ":" << line << ": ";
    std::cerr << "error: (" << description << ") failed\n";
    throw_require_failed(description, file, line);
}

} // namespace