system_error.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_SYSTEM_ERROR_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_SYSTEM_ERROR_HPP
3 
4 #include <typeinfo>
5 #include <sstream>
6 #include <stdexcept>
7 #include <system_error>
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Throw a system error with a consistently formatted message.
13  *
14  * This is an abstraction for all Stan functions to use when throwing
15  * system errors. This will allow us to change the behavior for all
16  * functions at once.
17  *
18  * The message is: "<function>: <name> <msg1><y><msg2>"
19  *
20  * @param[in] function Name of the function.
21  * @param[in] name Name of the variable.
22  * @param[in] y Error code.
23  * @param[in] msg1 Message to print before the variable.
24  * @param[in] msg2 Message to print after the variable.
25  * @throw std::system_error Always.
26  */
27 inline void system_error(const char* function, const char* name, const int& y,
28  const char* msg1, const char* msg2) {
29  std::ostringstream message;
30  // hack to remove -Waddress, -Wnonnull-compare warnings from GCC 6
31  message << function << ": " << name << " " << msg1 << msg2;
32  throw std::system_error(y, std::generic_category(), message.str());
33 }
34 
35 /**
36  * Throw a system error with a consistently formatted message.
37  *
38  * This is an abstraction for all Stan functions to use when throwing
39  * system errors. This will allow us to change the behavior for all
40  * functions at once.
41  *
42  * The message is: * "<function>: <name> <msg1><y>"
43  *
44  * @param[in] function Name of the function.
45  * @param[in] name Name of the variable.
46  * @param[in] y Error code.
47  * @param[in] msg1 Message to print before the variable.
48  * @throw std::system_error Always.
49  */
50 inline void system_error(const char* function, const char* name, const int& y,
51  const char* msg1) {
52  system_error(function, name, y, msg1, "");
53 }
54 
55 } // namespace math
56 } // namespace stan
57 #endif
const XML_Char * name
Definition: expat.h:151
void system_error(const char *function, const char *name, const int &y, const char *msg1, const char *msg2)
void system_error(const char *function, const char *name, const int &y, const char *msg1)