-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathexception.cpp
More file actions
52 lines (45 loc) · 1.1 KB
/
exception.cpp
File metadata and controls
52 lines (45 loc) · 1.1 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
*
* Written by Václav Kubernát <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <libyang-cpp/Utils.hpp>
#include <libyang/libyang.h>
#include <sstream>
#include "exception.hpp"
namespace libyang {
ErrorWithCode::ErrorWithCode(const std::string& what, unsigned int errCode)
: Error(what)
, m_errCode(static_cast<ErrorCode>(errCode))
{
}
ParsedInfoUnavailable::ParsedInfoUnavailable()
: Error("Context not created with libyang::ContextOptions::SetPrivParsed")
{
}
ParsedInfoUnavailable::ParsedInfoUnavailable(const std::string& what)
: Error(what)
{
}
ErrorCode ErrorWithCode::code() const
{
return m_errCode;
}
void throwIfError(int code, std::string msg)
{
if (code != LY_SUCCESS) {
throwError(code, msg);
}
}
[[noreturn]] void throwError(int code, std::string msg)
{
if (code == LY_SUCCESS) {
throw std::logic_error("Threw with LY_SUCCESS");
}
std::ostringstream oss;
oss << msg << ": " << static_cast<ErrorCode>(code);
throw ErrorWithCode(oss.str(), code);
}
}