ALPSCore reference
dict_exceptions.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
9 #ifndef ALPS_PARAMS_DICT_EXCEPTIONS_HPP_046b246d331b4e54bedf6bfef6e54a71
10 #define ALPS_PARAMS_DICT_EXCEPTIONS_HPP_046b246d331b4e54bedf6bfef6e54a71
11 
12 namespace alps {
13  namespace params_ns {
14 
15  namespace exception {
17  class exception_base : public std::runtime_error {
18  std::string name_;
19  mutable std::string what_;
20  public:
21  exception_base(const std::string& a_name, const std::string& a_reason)
22  : std::runtime_error(a_reason),
23  name_(a_name), what_(a_reason)
24  {}
25 
26  std::string name() const { return name_; }
27  void set_name(const std::string& name) { name_=name; }
28 
29  virtual const char* what() const throw() {
30  const std::string key(name_.empty() ? std::string("Unknown_key") : ("Key '"+name_+"'"));
31  what_=key+": "+std::runtime_error::what();
32  return what_.c_str();
33  }
34 
35  ~exception_base() throw() {}
36  };
37 
40  uninitialized_value (const std::string& a_name, const std::string& a_reason)
41  : exception_base(a_name, a_reason) {}
42  };
43 
45  struct type_mismatch : public exception_base {
46  type_mismatch(const std::string& a_name, const std::string& a_reason)
47  : exception_base(a_name, a_reason) {}
48  };
49 
51  struct value_mismatch : public exception_base {
52  value_mismatch(const std::string& a_name, const std::string& a_reason)
53  : exception_base(a_name, a_reason) {}
54  };
55 
56  // /// Exception for duplicated definition
58  double_definition(const std::string& a_name, const std::string& a_reason)
59  : exception_base(a_name, a_reason) {}
60  };
61 
62  } // ::exception
63  } // ::params_ns
64 } // ::alps
65 
66 #endif /* ALPS_PARAMS_DICT_EXCEPTIONS_HPP_046b246d331b4e54bedf6bfef6e54a71 */
void set_name(const std::string &name)
uninitialized_value(const std::string &a_name, const std::string &a_reason)
double_definition(const std::string &a_name, const std::string &a_reason)
STL namespace.
Exception for using uninitialized value.
value_mismatch(const std::string &a_name, const std::string &a_reason)
type_mismatch(const std::string &a_name, const std::string &a_reason)
General exception (base class)
exception_base(const std::string &a_name, const std::string &a_reason)