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