Add new exception types: communication, protocol, and invalid argument
[lttng-tools.git] / src / common / exception.cpp
CommitLineData
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"
9#include <sstream>
10#include <common/error.hpp>
11
12namespace {
13std::string format_throw_location(
baac5795 14 const char *file_name, const char *function_name, unsigned int line_number)
53cd1e22
JG
15{
16 std::stringstream location;
17
18 location << "[" << function_name << "()"
19 << " " << file_name << ":" << line_number << "]";
20
21 return location.str();
22}
baac5795 23} /* namespace */
53cd1e22
JG
24
25lttng::ctl::error::error(lttng_error_code error_code,
baac5795
JG
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)
53cd1e22
JG
30{
31}
32
baac5795
JG
33lttng::posix_error::posix_error(const std::string& msg,
34 int errno_code,
35 const char *file_name,
36 const char *function_name,
37 unsigned int line_number) :
53cd1e22 38 std::system_error(errno_code,
baac5795
JG
39 std::generic_category(),
40 msg + " " + format_throw_location(file_name, function_name, line_number))
53cd1e22
JG
41{
42}
aeeb48c6 43
baac5795
JG
44lttng::runtime_error::runtime_error(const std::string& msg,
45 const char *file_name,
46 const char *function_name,
47 unsigned int line_number) :
aeeb48c6
JG
48 std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
49{
50}
baac5795
JG
51
52lttng::communication_error::communication_error(const std::string& msg,
53 const char *file_name,
54 const char *function_name,
55 unsigned int line_number) :
56 runtime_error(msg, file_name, function_name, line_number)
57{
58}
59
60lttng::protocol_error::protocol_error(const std::string& msg,
61 const char *file_name,
62 const char *function_name,
63 unsigned int line_number) :
64 communication_error(msg, file_name, function_name, line_number)
65{
66}
67
68lttng::invalid_argument_error::invalid_argument_error(const std::string& msg,
69 const char *file_name,
70 const char *function_name,
71 unsigned int line_number) :
72 runtime_error(msg, file_name, function_name, line_number)
73{
74}
This page took 0.02514 seconds and 4 git commands to generate.