Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the KafkaException using modern practices #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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