2015-10-05 01:26:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
2015-10-05 01:26:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-09-07 21:04:48 +00:00
|
|
|
|
2018-11-22 18:09:17 +00:00
|
|
|
class NetException : public Exception
|
2015-10-05 01:26:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-08-02 03:03:24 +00:00
|
|
|
template <typename T>
|
|
|
|
requires std::is_convertible_v<T, String>
|
2023-01-23 21:13:58 +00:00
|
|
|
NetException(int code, T && message) : Exception(std::forward<T>(message), code)
|
|
|
|
{
|
|
|
|
message_format_string = tryGetStaticFormatString(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> NetException(int code, const String & message) : Exception(message, code) {}
|
|
|
|
template<> NetException(int code, String & message) : Exception(message, code) {}
|
|
|
|
template<> NetException(int code, String && message) : Exception(std::move(message), code) {}
|
2015-10-05 01:26:43 +00:00
|
|
|
|
2022-04-24 10:34:50 +00:00
|
|
|
// Format message with fmt::format, like the logging functions.
|
|
|
|
template <typename... Args>
|
2023-01-23 21:13:58 +00:00
|
|
|
NetException(int code, FormatStringHelper<Args...> fmt, Args &&... args)
|
|
|
|
: Exception(fmt::format(fmt.fmt_str, std::forward<Args>(args)...), code)
|
2022-04-24 10:34:50 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
message_format_string = fmt.message_format_string;
|
2022-04-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 18:09:17 +00:00
|
|
|
NetException * clone() const override { return new NetException(*this); }
|
|
|
|
void rethrow() const override { throw *this; }
|
2015-10-05 01:26:43 +00:00
|
|
|
|
2018-11-22 18:09:17 +00:00
|
|
|
private:
|
2022-05-16 18:59:27 +00:00
|
|
|
const char * name() const noexcept override { return "DB::NetException"; }
|
|
|
|
const char * className() const noexcept override { return "DB::NetException"; }
|
2015-10-05 01:26:43 +00:00
|
|
|
};
|
2017-09-07 21:04:48 +00:00
|
|
|
|
|
|
|
}
|