X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Fexception.cpp;fp=src%2Fcommon%2Fexception.cpp;h=16e27e52afa35ebd4e144363772c839602995e78;hb=53cd1e2272afac08649dc55e395ec8a5dac20b4e;hp=0000000000000000000000000000000000000000;hpb=47aa4f7bc50412db0818c83136814a9a1a0edf9a;p=lttng-tools.git diff --git a/src/common/exception.cpp b/src/common/exception.cpp new file mode 100644 index 000000000..16e27e52a --- /dev/null +++ b/src/common/exception.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#include "exception.hpp" +#include +#include + +namespace { +std::string format_throw_location( + const char *file_name, const char *function_name, unsigned int line_number) +{ + std::stringstream location; + + location << "[" << function_name << "()" + << " " << file_name << ":" << line_number << "]"; + + return location.str(); +} +} // namespace + +lttng::ctl::error::error(lttng_error_code error_code, + const char *file_name, + const char *function_name, + unsigned int line_number) : + std::runtime_error(std::string(error_get_str(error_code)) + " " + + format_throw_location(file_name, function_name, line_number)) +{ +} + +lttng::posix_error::posix_error(const std::string &msg, + int errno_code, + const char *file_name, + const char *function_name, + unsigned int line_number) : + std::system_error(errno_code, + std::generic_category(), + msg + " " + format_throw_location(file_name, function_name, line_number)) +{ +}