Build fix: missing header on macOS
[lttng-tools.git] / src / common / exception.cpp
CommitLineData
53cd1e22
JG
1/*
2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#include "exception.hpp"
28ab034a 9
53cd1e22
JG
10#include <common/error.hpp>
11
df28caaa
JG
12#include <lttng/lttng-error.h>
13
28ab034a
JG
14#include <sstream>
15
53cd1e22 16namespace {
28ab034a
JG
17std::string
18format_throw_location(const char *file_name, const char *function_name, unsigned int line_number)
53cd1e22
JG
19{
20 std::stringstream location;
21
22 location << "[" << function_name << "()"
23 << " " << file_name << ":" << line_number << "]";
24
25 return location.str();
26}
baac5795 27} /* namespace */
53cd1e22 28
0038180d
JG
29lttng::ctl::error::error(const std::string& msg,
30 lttng_error_code error_code,
28ab034a
JG
31 const char *file_name,
32 const char *function_name,
33 unsigned int line_number) :
0038180d
JG
34 runtime_error(msg + ": " + std::string(error_get_str(error_code)),
35 file_name,
36 function_name,
37 line_number),
28ab034a 38 _error_code{ error_code }
53cd1e22
JG
39{
40}
41
baac5795 42lttng::posix_error::posix_error(const std::string& msg,
28ab034a
JG
43 int errno_code,
44 const char *file_name,
45 const char *function_name,
46 unsigned int line_number) :
53cd1e22 47 std::system_error(errno_code,
28ab034a
JG
48 std::generic_category(),
49 msg + " " + format_throw_location(file_name, function_name, line_number))
53cd1e22
JG
50{
51}
aeeb48c6 52
baac5795 53lttng::runtime_error::runtime_error(const std::string& msg,
28ab034a
JG
54 const char *file_name,
55 const char *function_name,
56 unsigned int line_number) :
aeeb48c6
JG
57 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
58{
59}
baac5795 60
b6bbb1d6 61lttng::unsupported_error::unsupported_error(const std::string& msg,
28ab034a
JG
62 const char *file_name,
63 const char *function_name,
64 unsigned int line_number) :
b6bbb1d6
JG
65 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
66{
67}
68
baac5795 69lttng::communication_error::communication_error(const std::string& msg,
28ab034a
JG
70 const char *file_name,
71 const char *function_name,
72 unsigned int line_number) :
baac5795
JG
73 runtime_error(msg, file_name, function_name, line_number)
74{
75}
76
77lttng::protocol_error::protocol_error(const std::string& msg,
28ab034a
JG
78 const char *file_name,
79 const char *function_name,
80 unsigned int line_number) :
baac5795
JG
81 communication_error(msg, file_name, function_name, line_number)
82{
83}
84
85lttng::invalid_argument_error::invalid_argument_error(const std::string& msg,
28ab034a
JG
86 const char *file_name,
87 const char *function_name,
88 unsigned int line_number) :
baac5795
JG
89 runtime_error(msg, file_name, function_name, line_number)
90{
91}
This page took 0.034482 seconds and 4 git commands to generate.