X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fexception.hpp;fp=src%2Fcommon%2Fexception.hpp;h=20731c06aa4419f18daac0c2ff5a0622990cb559;hb=53cd1e2272afac08649dc55e395ec8a5dac20b4e;hp=0000000000000000000000000000000000000000;hpb=47aa4f7bc50412db0818c83136814a9a1a0edf9a;p=lttng-tools.git diff --git a/src/common/exception.hpp b/src/common/exception.hpp new file mode 100644 index 000000000..20731c06a --- /dev/null +++ b/src/common/exception.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Jérémie Galarneau + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_EXCEPTION_H_ +#define LTTNG_EXCEPTION_H_ + +#include +#include +#include + +#include + +#define LTTNG_THROW_CTL(error_code) \ + throw lttng::ctl::error(msg, error_code, __FILE__, __func__, __LINE__) +#define LTTNG_THROW_POSIX(msg, errno_code) \ + throw lttng::posix_error(msg, errno_code, __FILE__, __func__, __LINE__) + +namespace lttng { + +namespace ctl { +/* Wrap lttng_error_code errors which may be reported through liblttng-ctl's interface. */ +class error : public std::runtime_error { +public: + explicit error(lttng_error_code error_code, + const char *file_name, + const char *function_name, + unsigned int line_number); + lttng_error_code get_code() const; + +private: + lttng_error_code _error_code; +}; +} /* namespace ctl */ + +class posix_error : public std::system_error { +public: + explicit posix_error(const std::string &msg, + int errno_code, + const char *file_name, + const char *function_name, + unsigned int line_number); +}; + +}; /* namespace lttng */ + +#endif /* LTTNG_EXCEPTION_H_ */