Run clang-format on the whole tree
[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(lttng_error_code error_code,
28 const char *file_name,
29 const char *function_name,
30 unsigned int line_number) :
31 runtime_error(
32 std::string(error_get_str(error_code)), file_name, function_name, line_number),
33 _error_code{ error_code }
34 {
35 }
36
37 lttng::posix_error::posix_error(const std::string& msg,
38 int errno_code,
39 const char *file_name,
40 const char *function_name,
41 unsigned int line_number) :
42 std::system_error(errno_code,
43 std::generic_category(),
44 msg + " " + format_throw_location(file_name, function_name, line_number))
45 {
46 }
47
48 lttng::runtime_error::runtime_error(const std::string& msg,
49 const char *file_name,
50 const char *function_name,
51 unsigned int line_number) :
52 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
53 {
54 }
55
56 lttng::unsupported_error::unsupported_error(const std::string& msg,
57 const char *file_name,
58 const char *function_name,
59 unsigned int line_number) :
60 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
61 {
62 }
63
64 lttng::communication_error::communication_error(const std::string& msg,
65 const char *file_name,
66 const char *function_name,
67 unsigned int line_number) :
68 runtime_error(msg, file_name, function_name, line_number)
69 {
70 }
71
72 lttng::protocol_error::protocol_error(const std::string& msg,
73 const char *file_name,
74 const char *function_name,
75 unsigned int line_number) :
76 communication_error(msg, file_name, function_name, line_number)
77 {
78 }
79
80 lttng::invalid_argument_error::invalid_argument_error(const std::string& msg,
81 const char *file_name,
82 const char *function_name,
83 unsigned int line_number) :
84 runtime_error(msg, file_name, function_name, line_number)
85 {
86 }
This page took 0.030649 seconds and 4 git commands to generate.