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

Added RdKafkaException base class #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 18 additions & 17 deletions include/cppkafka/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class CPPKAFKA_API Exception : public std::exception {
std::string message_;
};

/**
* Base class for all rdkafka exceptions
*/
class CPPKAFKA_API RdKafkaException : public Exception {
public:
RdKafkaException(Error error);
RdKafkaException(Error error, std::string message);

Error get_error() const noexcept;
private:
Error error_;
};

/**
* A configuration related error
*/
Expand Down Expand Up @@ -87,7 +100,7 @@ class CPPKAFKA_API ElementNotFound : public Exception {
*/
class CPPKAFKA_API ParseException : public Exception {
public:
ParseException(const std::string& message);
ParseException(std::string message);
};

/**
Expand All @@ -101,45 +114,33 @@ class CPPKAFKA_API UnexpectedVersion : public Exception {
/**
* A generic rdkafka handle error
*/
class CPPKAFKA_API HandleException : public Exception {
class CPPKAFKA_API HandleException : public RdKafkaException {
public:
HandleException(Error error);

Error get_error() const;
private:
Error error_;
};

/**
* Consumer exception
*/
class CPPKAFKA_API ConsumerException : public Exception {
class CPPKAFKA_API ConsumerException : public RdKafkaException {
public:
ConsumerException(Error error);

Error get_error() const;
private:
Error error_;
};

/**
* Queue exception for rd_kafka_queue_t errors
*/
class CPPKAFKA_API QueueException : public Exception {
class CPPKAFKA_API QueueException : public RdKafkaException {
public:
QueueException(Error error);

Error get_error() const;
private:
Error error_;
};

/**
* Backoff performer has no more retries left for a specific action.
*/
class CPPKAFKA_API ActionTerminatedException : public Exception {
public:
ActionTerminatedException(const std::string& error);
ActionTerminatedException(std::string message);
};

} // cppkafka
Expand Down
45 changes: 26 additions & 19 deletions src/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using std::string;
using std::to_string;
using std::move;

namespace cppkafka {

Expand All @@ -45,6 +46,24 @@ const char* Exception::what() const noexcept {
return message_.data();
}

// RdKafkaException

RdKafkaException::RdKafkaException(Error error)
: Exception(error.to_string())
, error_(move(error)) {

}

RdKafkaException::RdKafkaException(Error error, string message)
: Exception(move(message))
, error_(move(error)) {

}

Error RdKafkaException::get_error() const noexcept {
return error_;
}

// ConfigException

ConfigException::ConfigException(const string& config_name, const string& error)
Expand Down Expand Up @@ -75,8 +94,8 @@ ElementNotFound::ElementNotFound(const string& element_type, const string& name)

// ParseException

ParseException::ParseException(const string& message)
: Exception(message) {
ParseException::ParseException(string message)
: Exception(move(message)) {

}

Expand All @@ -89,40 +108,28 @@ UnexpectedVersion::UnexpectedVersion(uint32_t version)
// HandleException

HandleException::HandleException(Error error)
: Exception(error.to_string()), error_(error) {
: RdKafkaException(move(error)) {

}

Error HandleException::get_error() const {
return error_;
}

// ConsumerException

ConsumerException::ConsumerException(Error error)
: Exception(error.to_string()), error_(error) {
: RdKafkaException(move(error)) {

}

Error ConsumerException::get_error() const {
return error_;
}

// QueueException

QueueException::QueueException(Error error)
: Exception(error.to_string()), error_(error) {

}
: RdKafkaException(move(error)) {

Error QueueException::get_error() const {
return error_;
}

// ActionTerminatedException

ActionTerminatedException::ActionTerminatedException(const string& error)
: Exception(error) {
ActionTerminatedException::ActionTerminatedException(string message)
: Exception(move(message)) {

}

Expand Down