Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dom_err.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING__DOM_ERR_HPP
2 #define STAN__MATH__ERROR_HANDLING__DOM_ERR_HPP
3 
4 #include <typeinfo>
5 #ifdef BOOST_MSVC
6 # pragma warning(push) // Quiet warnings in boost/format.hpp
7 # pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE
8 # pragma warning(disable: 4512) // assignment operator could not be generated.
9 // And warnings in error handling:
10 # pragma warning(disable: 4702) // unreachable code
11 // Note that this only occurs when the compiler can deduce code is unreachable,
12 // for example when policy macros are used to ignore errors rather than throw.
13 #endif
14 #include <boost/format.hpp>
15 
16 #include <sstream>
17 #include <stdexcept>
18 
19 namespace stan {
20  namespace math {
21 
22  namespace {
23  // local output stream for pairs
24  template <typename T1, typename T2>
25  std::ostream& operator<<(std::ostream& o,
26  std::pair<T1,T2> xs) {
27  o << '(' << xs.first << ", " << xs.second << ')';
28  return o;
29  }
30  }
31 
32  // currently ignoring T_result
33  template <typename T,
34  typename T_result,
35  typename T_msg>
36  inline bool dom_err(const char* function,
37  const T& y,
38  const char* name,
39  const char* error_msg,
40  const T_msg error_msg2,
41  T_result* result) {
42  std::ostringstream msg_o;
43  msg_o << name << error_msg << error_msg2;
44 
45  std::string msg;
46  msg += (boost::format(function) % typeid(T).name()).str();
47  msg += ": ";
48  msg += msg_o.str();
49 
50  throw std::domain_error((boost::format(msg) % y).str());
51 
52  return false;
53  }
54 
55 
56  }
57 }
58 #endif
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
std::ostream & operator<<(std::ostream &o, const expr_type &et)
Definition: ast_def.cpp:118

     [ Stan Home Page ] © 2011–2014, Stan Development Team.