38__JAFFAR_COMMON__INLINE__
void throwException [[noreturn]] (
const char* exceptionType,
const char* fileName,
const int lineNumber,
const char* format, ...)
43 int ret = vsnprintf(
nullptr, 0, format, ap);
45 if (ret < 0)
throw std::invalid_argument(
"Failed processing exception reason");
47 outstr = (
char*)malloc(ret + 1);
48 if (outstr ==
nullptr)
throw std::invalid_argument(
"Failed processing exception reason");
51 ret = vsnprintf(outstr, ret + 1, format, ap);
56 throw std::invalid_argument(
"Failed processing exception reason");
59 std::string outString = outstr;
64 snprintf(info,
sizeof(info) - 1,
" + From %s:%d\n", fileName, lineNumber);
67 if (std::string(exceptionType) ==
"Logic")
throw std::logic_error(outString.c_str());
68 if (std::string(exceptionType) ==
"Runtime")
throw std::runtime_error(outString.c_str());
69 throw std::invalid_argument(
"Wrong exception type provided: " + std::string(exceptionType) + std::string(
" Original error: ") + outString);
__JAFFAR_COMMON__INLINE__ void throwException(const char *exceptionType, const char *fileName, const int lineNumber, const char *format,...)
Definition exceptions.hpp:38