Move the lttng::free util under the lttng::memory namespace
[lttng-tools.git] / src / common / exception.cpp
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"
9
10 #include <common/error.hpp>
11
12 #include <sstream>
13
14 namespace {
15 std::string
16 format_throw_location(const char *file_name, const char *function_name, unsigned int line_number)
17 {
18 std::stringstream location;
19
20 location << "[" << function_name << "()"
21 << " " << file_name << ":" << line_number << "]";
22
23 return location.str();
24 }
25 } /* namespace */
26
27 lttng::ctl::error::error(const std::string& msg,
28 lttng_error_code error_code,
29 const char *file_name,
30 const char *function_name,
31 unsigned int line_number) :
32 runtime_error(msg + ": " + std::string(error_get_str(error_code)),
33 file_name,
34 function_name,
35 line_number),
36 _error_code{ error_code }
37 {
38 }
39
40 lttng::posix_error::posix_error(const std::string& msg,
41 int errno_code,
42 const char *file_name,
43 const char *function_name,
44 unsigned int line_number) :
45 std::system_error(errno_code,
46 std::generic_category(),
47 msg + " " + format_throw_location(file_name, function_name, line_number))
48 {
49 }
50
51 lttng::runtime_error::runtime_error(const std::string& msg,
52 const char *file_name,
53 const char *function_name,
54 unsigned int line_number) :
55 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
56 {
57 }
58
59 lttng::unsupported_error::unsupported_error(const std::string& msg,
60 const char *file_name,
61 const char *function_name,
62 unsigned int line_number) :
63 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
64 {
65 }
66
67 lttng::communication_error::communication_error(const std::string& msg,
68 const char *file_name,
69 const char *function_name,
70 unsigned int line_number) :
71 runtime_error(msg, file_name, function_name, line_number)
72 {
73 }
74
75 lttng::protocol_error::protocol_error(const std::string& msg,
76 const char *file_name,
77 const char *function_name,
78 unsigned int line_number) :
79 communication_error(msg, file_name, function_name, line_number)
80 {
81 }
82
83 lttng::invalid_argument_error::invalid_argument_error(const std::string& msg,
84 const char *file_name,
85 const char *function_name,
86 unsigned int line_number) :
87 runtime_error(msg, file_name, function_name, line_number)
88 {
89 }
This page took 0.057076 seconds and 4 git commands to generate.