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 JG |
26 | |
27 | lttng::ctl::error::error(lttng_error_code error_code, | |
28ab034a JG |
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 } | |
53cd1e22 JG |
34 | { |
35 | } | |
36 | ||
baac5795 | 37 | lttng::posix_error::posix_error(const std::string& msg, |
28ab034a JG |
38 | int errno_code, |
39 | const char *file_name, | |
40 | const char *function_name, | |
41 | unsigned int line_number) : | |
53cd1e22 | 42 | std::system_error(errno_code, |
28ab034a JG |
43 | std::generic_category(), |
44 | msg + " " + format_throw_location(file_name, function_name, line_number)) | |
53cd1e22 JG |
45 | { |
46 | } | |
aeeb48c6 | 47 | |
baac5795 | 48 | lttng::runtime_error::runtime_error(const std::string& msg, |
28ab034a JG |
49 | const char *file_name, |
50 | const char *function_name, | |
51 | unsigned int line_number) : | |
aeeb48c6 JG |
52 | std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number)) |
53 | { | |
54 | } | |
baac5795 | 55 | |
b6bbb1d6 | 56 | lttng::unsupported_error::unsupported_error(const std::string& msg, |
28ab034a JG |
57 | const char *file_name, |
58 | const char *function_name, | |
59 | unsigned int line_number) : | |
b6bbb1d6 JG |
60 | std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number)) |
61 | { | |
62 | } | |
63 | ||
baac5795 | 64 | lttng::communication_error::communication_error(const std::string& msg, |
28ab034a JG |
65 | const char *file_name, |
66 | const char *function_name, | |
67 | unsigned int line_number) : | |
baac5795 JG |
68 | runtime_error(msg, file_name, function_name, line_number) |
69 | { | |
70 | } | |
71 | ||
72 | lttng::protocol_error::protocol_error(const std::string& msg, | |
28ab034a JG |
73 | const char *file_name, |
74 | const char *function_name, | |
75 | unsigned int line_number) : | |
baac5795 JG |
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, | |
28ab034a JG |
81 | const char *file_name, |
82 | const char *function_name, | |
83 | unsigned int line_number) : | |
baac5795 JG |
84 | runtime_error(msg, file_name, function_name, line_number) |
85 | { | |
86 | } |