Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

governance-exceptions.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef GOVERNANCE_EXCEPTIONS_H
6 #define GOVERNANCE_EXCEPTIONS_H
7 
8 #include <exception>
9 #include <iostream>
10 #include <sstream>
11 #include <string>
12 
24 };
25 
26 inline std::ostream& operator<<(std::ostream& os, governance_exception_type_enum_t eType)
27 {
28  switch (eType) {
30  os << "GOVERNANCE_EXCEPTION_NONE";
31  break;
33  os << "GOVERNANCE_EXCEPTION_WARNING";
34  break;
36  os << "GOVERNANCE_EXCEPTION_PERMANENT_ERROR";
37  break;
39  os << "GOVERNANCE_EXCEPTION_TEMPORARY_ERROR";
40  break;
42  os << "GOVERNANCE_EXCEPTION_INTERNAL_ERROR";
43  break;
44  }
45  return os;
46 }
47 
55 class CGovernanceException : public std::exception
56 {
57 private:
58  std::string strMessage;
59 
61 
63 
64 public:
65  CGovernanceException(const std::string& strMessageIn = "",
67  int nNodePenaltyIn = 0) :
68  strMessage(),
69  eType(eTypeIn),
70  nNodePenalty(nNodePenaltyIn)
71  {
72  std::ostringstream ostr;
73  ostr << eType << ":" << strMessageIn;
74  strMessage = ostr.str();
75  }
76 
77  virtual ~CGovernanceException() noexcept {}
78 
79  virtual const char* what() const noexcept override
80  {
81  return strMessage.c_str();
82  }
83 
84  const std::string& GetMessage() const
85  {
86  return strMessage;
87  }
88 
90  {
91  return eType;
92  }
93 
94  int GetNodePenalty() const
95  {
96  return nNodePenalty;
97  }
98 };
99 
100 #endif
virtual ~CGovernanceException() noexcept
Default value, normally indicates no exception condition occurred.
governance_exception_type_enum_t GetType() const
Requested operation cannot be performed.
Unexpected error (ie. should not happen unless there is a bug in the code)
Requested operation not currently possible, may resubmit later.
std::ostream & operator<<(std::ostream &os, governance_exception_type_enum_t eType)
A class which encapsulates information about a governance exception condition.
virtual const char * what() const noexcept override
governance_exception_type_enum_t eType
governance_exception_type_enum_t
Unusual condition requiring no caller action.
const std::string & GetMessage() const
CGovernanceException(const std::string &strMessageIn="", governance_exception_type_enum_t eTypeIn=GOVERNANCE_EXCEPTION_NONE, int nNodePenaltyIn=0)
Released under the MIT license