From d117f9c77783ba0287081cf870e4469b2d7fc7a5 Mon Sep 17 00:00:00 2001 From: downfa11 Date: Fri, 13 Sep 2024 14:20:46 +0900 Subject: [PATCH] Refactor kafkaException constructor C++20 source_location --- include/kafka/KafkaException.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/kafka/KafkaException.h b/include/kafka/KafkaException.h index a4fd3d5dd..a9f822cd2 100644 --- a/include/kafka/KafkaException.h +++ b/include/kafka/KafkaException.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace KAFKA_API { @@ -21,10 +22,10 @@ namespace KAFKA_API { class KafkaException: public std::exception { public: - KafkaException(const char* filename, std::size_t lineno, const Error& error) + KafkaException(const std::source_location location = std::source_location::current(), const Error& error) : _when(std::chrono::system_clock::now()), - _filename(filename), - _lineno(lineno), + _filename(location.file_name()), + _lineno(location.line()), _error(std::make_shared(error)) {} @@ -53,7 +54,7 @@ class KafkaException: public std::exception }; -#define KAFKA_THROW_ERROR(error) throw KafkaException(__FILE__, __LINE__, error) +#define KAFKA_THROW_ERROR(error) throw KafkaException(error) #define KAFKA_THROW_IF_WITH_ERROR(error) if (error) KAFKA_THROW_ERROR(error) } // end of KAFKA_API