NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
Error.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <iostream>
31#include <stdexcept>
32#include <string>
33
34#include "NumCpp/Core/Types.hpp"
35
36// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
37#define THROW_INVALID_ARGUMENT_ERROR(msg) \
38 nc::error::throwError<std::invalid_argument>(__FILE__, __func__, __LINE__, msg)
39// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
40#define THROW_RUNTIME_ERROR(msg) nc::error::throwError<std::runtime_error>(__FILE__, __func__, __LINE__, msg)
41
42namespace nc::error
43{
44 //============================================================================
52 template<typename ErrorType>
53 void throwError(const std::string& file, const std::string& function, uint32 line, const std::string& msg = "")
54 {
55 std::string errMsg =
56 "File: " + file + "\n\tFunction: " + function + "\n\tLine: " + std::to_string(line) + "\n\tError: " + msg;
57 std::cerr << errMsg;
58 throw ErrorType(errMsg);
59 }
60} // namespace nc::error
Definition: Error.hpp:43
void throwError(const std::string &file, const std::string &function, uint32 line, const std::string &msg="")
Definition: Error.hpp:53
std::uint32_t uint32
Definition: Types.hpp:40