Commit | Line | Data |
---|---|---|
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 | ||
28ab034a JG |
12 | #include <sstream> |
13 | ||
53cd1e22 | 14 | namespace { |
28ab034a JG |
15 | std::string |
16 | format_throw_location(const char *file_name, const char *function_name, unsigned int line_number) | |
53cd1e22 JG |
17 | { |
18 | std::stringstream location; | |
19 | ||
20 | location << "[" << function_name << "()" | |
21 | << " " << file_name << ":" << line_number << "]"; | |
22 | ||
23 | return location.str(); | |
24 | } | |
baac5795 | 25 | } /* namespace */ |
53cd1e22 | 26 | |
0038180d JG |
27 | lttng::ctl::error::error(const std::string& msg, |
28 | lttng_error_code error_code, | |
28ab034a JG |
29 | const char *file_name, |
30 | const char *function_name, | |
31 | unsigned int line_number) : | |
0038180d JG |
32 | runtime_error(msg + ": " + std::string(error_get_str(error_code)), |
33 | file_name, | |
34 | function_name, | |
35 | line_number), | |
28ab034a | 36 | _error_code{ error_code } |
53cd1e22 JG |
37 | { |
38 | } | |
39 | ||
baac5795 | 40 | lttng::posix_error::posix_error(const std::string& msg, |
28ab034a JG |
41 | int errno_code, |
42 | const char *file_name, | |
43 | const char *function_name, | |
44 | unsigned int line_number) : | |
53cd1e22 | 45 | std::system_error(errno_code, |
28ab034a JG |
46 | std::generic_category(), |
47 | msg + " " + format_throw_location(file_name, function_name, line_number)) | |
53cd1e22 JG |
48 | { |
49 | } | |
aeeb48c6 | 50 | |
baac5795 | 51 | lttng::runtime_error::runtime_error(const std::string& msg, |
28ab034a JG |
52 | const char *file_name, |
53 | const char *function_name, | |
54 | unsigned int line_number) : | |
aeeb48c6 JG |
55 | std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number)) |
56 | { | |
57 | } | |
baac5795 | 58 | |
b6bbb1d6 | 59 | lttng::unsupported_error::unsupported_error(const std::string& msg, |
28ab034a JG |
60 | const char *file_name, |
61 | const char *function_name, | |
62 | unsigned int line_number) : | |
b6bbb1d6 JG |
63 | std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number)) |
64 | { | |
65 | } | |
66 | ||
baac5795 | 67 | lttng::communication_error::communication_error(const std::string& msg, |
28ab034a JG |
68 | const char *file_name, |
69 | const char *function_name, | |
70 | unsigned int line_number) : | |
baac5795 JG |
71 | runtime_error(msg, file_name, function_name, line_number) |
72 | { | |
73 | } | |
74 | ||
75 | lttng::protocol_error::protocol_error(const std::string& msg, | |
28ab034a JG |
76 | const char *file_name, |
77 | const char *function_name, | |
78 | unsigned int line_number) : | |
baac5795 JG |
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, | |
28ab034a JG |
84 | const char *file_name, |
85 | const char *function_name, | |
86 | unsigned int line_number) : | |
baac5795 JG |
87 | runtime_error(msg, file_name, function_name, line_number) |
88 | { | |
89 | } |