diff --git a/include/limestone/api/limestone_exception.h b/include/limestone/api/limestone_exception.h index 221b68ce..73785a82 100644 --- a/include/limestone/api/limestone_exception.h +++ b/include/limestone/api/limestone_exception.h @@ -22,6 +22,7 @@ #include #include + namespace limestone::api { class limestone_exception : public std::runtime_error { @@ -54,26 +55,4 @@ class limestone_io_exception : public limestone_exception { } }; -// Macro to throw exceptions with file and line information - -#define THROW_LIMESTONE_EXCEPTION(message) \ - throw limestone_exception(std::string(message) + " (at " + std::filesystem::path(__FILE__).filename().string() + ":" + std::to_string(__LINE__) + ")") - -#define THROW_LIMESTONE_IO_EXCEPTION(message, error_code) \ - throw limestone_io_exception(std::string(message) + " (at " + std::filesystem::path(__FILE__).filename().string() + ":" + std::to_string(__LINE__) + ")", error_code) - -#define LOG_AND_THROW_EXCEPTION(message) \ - { \ - LOG_LP(ERROR) << message; \ - THROW_LIMESTONE_EXCEPTION(message); \ - } - -#define LOG_AND_THROW_IO_EXCEPTION(message, error_code) \ - { \ - std::string full_message = limestone_io_exception::format_message(message, error_code); \ - LOG_LP(ERROR) << full_message; \ - THROW_LIMESTONE_IO_EXCEPTION(message, error_code); \ - } - - } // namespace limestone::api diff --git a/src/limestone/compaction_catalog.cpp b/src/limestone/compaction_catalog.cpp index 58f0f261..0a8fdc77 100644 --- a/src/limestone/compaction_catalog.cpp +++ b/src/limestone/compaction_catalog.cpp @@ -27,7 +27,7 @@ #include "compaction_catalog.h" #include "logging_helper.h" #include "limestone/api/epoch_id_type.h" -#include "limestone/api/limestone_exception.h" +#include "limestone_exception_helper.h" namespace limestone::internal { diff --git a/src/limestone/limestone_exception_helper.h b/src/limestone/limestone_exception_helper.h new file mode 100644 index 00000000..2aceac2e --- /dev/null +++ b/src/limestone/limestone_exception_helper.h @@ -0,0 +1,45 @@ +#include +#include +#include "logging_helper.h" + +#include + +#pragma once + +namespace limestone { + +using limestone::api::limestone_exception; +using limestone::api::limestone_io_exception; + +inline void throw_limestone_exception(const std::string& message, const char* file, int line) { + throw limestone_exception(message + " (at " + std::filesystem::path(file).filename().string() + ":" + std::to_string(line) + ")"); +} + +inline void throw_limestone_io_exception(const std::string& message, int error_code, const char* file, int line) { + throw limestone_io_exception(message + " (at " + std::filesystem::path(file).filename().string() + ":" + std::to_string(line) + ")", error_code); +} + +inline void log_and_throw_exception(const std::string& message, const char* file, int line) { + LOG_LP(ERROR) << message; + throw_limestone_exception(message, file, line); +} + +inline void log_and_throw_io_exception(const std::string& message, int error_code, const char* file, int line) { + std::string full_message = limestone_io_exception::format_message(message, error_code); + LOG_LP(ERROR) << full_message; + throw_limestone_io_exception(message, error_code, file, line); +} + +// NOLINTNEXTLINE +#define THROW_LIMESTONE_EXCEPTION(message) throw_limestone_exception(message, __FILE__, __LINE__) + +// NOLINTNEXTLINE +#define THROW_LIMESTONE_IO_EXCEPTION(message, error_code) throw_limestone_io_exception(message, error_code, __FILE__, __LINE__) + +// NOLINTNEXTLINE +#define LOG_AND_THROW_EXCEPTION(message) log_and_throw_exception(message, __FILE__, __LINE__) + +// NOLINTNEXTLINE +#define LOG_AND_THROW_IO_EXCEPTION(message, error_code) log_and_throw_io_exception(message, error_code, __FILE__, __LINE__) + +} // namespace limestone \ No newline at end of file