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