domain_error_vec.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_DOMAIN_ERROR_VEC_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_DOMAIN_ERROR_VEC_HPP
3 
8 #include <sstream>
9 #include <string>
10 
11 namespace stan {
12 namespace math {
13 
14 /**
15  * Throw a domain error with a consistently formatted message.
16  *
17  * This is an abstraction for all Stan functions to use when throwing
18  * domain errors. This will allow us to change the behavior for all
19  * functions at once. (We've already changed behavior mulitple times up
20  * to Stan v2.5.0.)
21  *
22  * The message is:
23  * "<function>: <name>[<i+error_index>] <msg1><y>"
24  * where error_index is the value of stan::error_index::value
25  * which indicates whether the message should be 0 or 1 indexed.
26  *
27  * @tparam T Type of variable
28  * @param function Name of the function
29  * @param name Name of the variable
30  * @param y Variable
31  * @param i Index
32  * @param msg1 Message to print before the variable
33  * @param msg2 Message to print after the variable
34  * @throw std::domain_error
35  */
36 template <typename T>
37 inline void domain_error_vec(const char* function, const char* name, const T& y,
38  size_t i, const char* msg1, const char* msg2) {
39  std::ostringstream vec_name_stream;
40  vec_name_stream << name << "[" << stan::error_index::value + i << "]";
41  std::string vec_name(vec_name_stream.str());
42  domain_error(function, vec_name.c_str(), stan::get(y, i), msg1, msg2);
43 }
44 
45 /**
46  * Throw a domain error with a consistently formatted message.
47  *
48  * This is an abstraction for all Stan functions to use when throwing
49  * domain errors. This will allow us to change the behavior for all
50  * functions at once. (We've already changed behavior mulitple times up
51  * to Stan v2.5.0.)
52  *
53  * The message is:
54  * "<function>: <name>[<i+error_index>] <msg1><y>"
55  * where error_index is the value of stan::error_index::value
56  * which indicates whether the message should be 0 or 1 indexed.
57  *
58  * @tparam T Type of variable
59  * @param function Name of the function
60  * @param name Name of the variable
61  * @param y Variable
62  * @param i Index
63  * @param msg Message to print before the variable
64  * @throw std::domain_error
65  */
66 template <typename T>
67 inline void domain_error_vec(const char* function, const char* name, const T& y,
68  size_t i, const char* msg) {
69  domain_error_vec(function, name, y, i, msg, "");
70 }
71 
72 } // namespace math
73 } // namespace stan
74 #endif
const XML_Char * name
Definition: expat.h:151
void domain_error_vec(const char *function, const char *name, const T &y, size_t i, const char *msg1, const char *msg2)
T get(const std::vector< T > &x, size_t n)
Definition: get.hpp:10
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
double T
Definition: Xdiff_gwt.C:5
enum BeamMode string