Skip to content

Commit b0793aa

Browse files
committed
Refactor kafkaException constructor
C++20 source_location
1 parent 268133a commit b0793aa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

include/kafka/KafkaException.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <chrono>
1212
#include <exception>
1313
#include <string>
14+
#include <source_location>
1415

1516

1617
namespace KAFKA_API {
@@ -21,10 +22,10 @@ namespace KAFKA_API {
2122
class KafkaException: public std::exception
2223
{
2324
public:
24-
KafkaException(const char* filename, std::size_t lineno, const Error& error)
25+
KafkaException(const std::source_location location = std::source_location::current(), const Error& error)
2526
: _when(std::chrono::system_clock::now()),
26-
_filename(filename),
27-
_lineno(lineno),
27+
_filename(location.file_name()),
28+
_lineno(location.line()),
2829
_error(std::make_shared<Error>(error))
2930
{}
3031

@@ -53,7 +54,7 @@ class KafkaException: public std::exception
5354
};
5455

5556

56-
#define KAFKA_THROW_ERROR(error) throw KafkaException(__FILE__, __LINE__, error)
57+
#define KAFKA_THROW_ERROR(error) throw KafkaException(error)
5758
#define KAFKA_THROW_IF_WITH_ERROR(error) if (error) KAFKA_THROW_ERROR(error)
5859

5960
} // end of KAFKA_API

0 commit comments

Comments
 (0)