26 #ifndef CASADI_EXCEPTION_HPP
27 #define CASADI_EXCEPTION_HPP
39 #include <casadi/core/casadi_export.h>
45 #pragma warning(disable:4251)
49 #pragma warning(disable:4275)
53 #pragma warning(disable:4996)
90 const char*
what()
const throw()
override {
107 inline std::string
trim_path(
const std::string& full_path) {
108 size_t found = full_path.rfind(
"/casadi/");
109 if (found == std::string::npos) {
112 std::string ret = full_path;
113 ret.replace(0, found,
"...");
121 stream <<
"CasADi - ";
123 auto now = std::chrono::system_clock::now();
124 std::time_t tt = std::chrono::system_clock::to_time_t(now);
125 auto local_tm = *std::localtime(&tt);
127 stream << local_tm.tm_year + 1900 <<
'-';
128 stream << std::setfill(
'0') << std::setw(2) << local_tm.tm_mon + 1 <<
'-';
129 stream << std::setfill(
'0') << std::setw(2) << local_tm.tm_mday <<
' ';
130 stream << std::setfill(
'0') << std::setw(2) << local_tm.tm_hour <<
':';
131 stream << std::setfill(
'0') << std::setw(2) << local_tm.tm_min <<
':';
132 stream << std::setfill(
'0') << std::setw(2) << local_tm.tm_sec;
137 #define CASADI_WHERE casadi::trim_path(__FILE__ ":" CASADI_STR(__LINE__))
140 #define casadi_error(msg, ...) \
141 throw casadi::CasadiException(CASADI_WHERE + ": "\
142 + casadi::fmtstr(msg, casadi::strvec(__VA_ARGS__)))
145 #define casadi_assert(x, msg, ...) \
146 if (!(x)) casadi_error("Assertion \"" CASADI_STR(x) "\" failed:\n"\
147 + std::string(msg), __VA_ARGS__)
150 #define casadi_assert_dev(x) casadi_assert(x, "Notify the CasADi developers.")
153 #define casadi_report() casadi_error("Notify the CasADi developers.")
156 #define casadi_warning(msg) \
157 casadi::message_prefix(casadi::uerr()) \
158 << " WARNING(\"" << msg << "\") [" << CASADI_WHERE << "]\n" << std::flush;
161 #define casadi_message(msg) \
162 casadi::message_prefix(casadi::uout()) \
163 << " MESSAGE(\"" << msg << "\") [" << CASADI_WHERE << "]\n" << std::flush;
~CasadiException()
Destructor.
const char * what() const override
Display error.
CasadiException(const std::string &msg)
Form message string.
CasadiException()
Default constructor.
KeyboardInterruptException()
Default constructor.
~KeyboardInterruptException()
Destructor.
std::ostream & message_prefix(std::ostream &stream)
std::string trim_path(const std::string &full_path)