Skip to content

Commit

Permalink
Refactor kafkaException constructor
Browse files Browse the repository at this point in the history
C++20 source_location
  • Loading branch information
downfa11 committed Sep 13, 2024
1 parent 122678e commit d117f9c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/kafka/KafkaException.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <chrono>
#include <exception>
#include <string>
#include <source_location>


namespace KAFKA_API {
Expand All @@ -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>(error))
{}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d117f9c

Please sign in to comment.