#ifndef BWIDGETS_EXCEPTION_HPP #define BWIDGETS_EXCEPTION_HPP #include #include #include #include #include namespace bwidgets { struct BaseException : std::exception { const char* file; const char* func; const int line; const char* what; BaseException(const char* file, const char* func, int l, const char* w) : file(file), func(func), line(l), what(w) {} }; template concept Exception = std::derived_from; template static inline auto ptr_or_throw(T* ptr, const char* file, const char* func, const int l, const char* w = nullptr) -> T* { if (ptr == nullptr) throw E(file, func, l, w); return ptr; } template static inline auto success_or_throw( T code, const char* file, const char* func, const int l, const char* w = nullptr, std::function success = [](const T& code) { return code == 0; }) -> T { if (!success(code)) throw E(file, func, l, w); return code; } } #endif