mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-17 19:31:35 +02:00
Runtime/LogicError and throwers
This commit is contained in:
parent
75279ccec2
commit
5383794cc9
@ -35,15 +35,20 @@ namespace Json {
|
|||||||
|
|
||||||
/** Base class for all exceptions we throw.
|
/** Base class for all exceptions we throw.
|
||||||
*/
|
*/
|
||||||
class Exception : public std::exception {
|
class JSON_API Exception;
|
||||||
public:
|
/** Exceptions which the user cannot easily avoid.
|
||||||
Exception(std::string const& msg);
|
*
|
||||||
virtual ~Exception() throw();
|
* E.g. out-of-memory, stack-overflow, malicious input
|
||||||
virtual char const* what() const throw();
|
*/
|
||||||
protected:
|
class JSON_API RuntimeError;
|
||||||
std::string const& msg_;
|
/** Exceptions throw by JSON_ASSERT/JSON_FAIL macros.
|
||||||
void* future_use_;
|
*
|
||||||
};
|
* These are precondition-violations (user bugs) and internal errors (our bugs).
|
||||||
|
*/
|
||||||
|
class JSON_API LogicError;
|
||||||
|
|
||||||
|
JSON_API void throwRuntimeError(std::string const& msg);
|
||||||
|
JSON_API void throwLogicError(std::string const& msg);
|
||||||
|
|
||||||
/** \brief Type of the value held by a Value object.
|
/** \brief Type of the value held by a Value object.
|
||||||
*/
|
*/
|
||||||
|
@ -152,17 +152,46 @@ static inline void releaseStringValue(char* value) { free(value); }
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
|
class JSON_API Exception : public std::exception {
|
||||||
|
public:
|
||||||
|
Exception(std::string const& msg);
|
||||||
|
virtual ~Exception() throw();
|
||||||
|
virtual char const* what() const throw();
|
||||||
|
protected:
|
||||||
|
std::string const& msg_;
|
||||||
|
};
|
||||||
|
class JSON_API RuntimeError : public Exception {
|
||||||
|
public:
|
||||||
|
RuntimeError(std::string const& msg);
|
||||||
|
};
|
||||||
|
class JSON_API LogicError : public Exception {
|
||||||
|
public:
|
||||||
|
LogicError(std::string const& msg);
|
||||||
|
};
|
||||||
|
|
||||||
Exception::Exception(std::string const& msg)
|
Exception::Exception(std::string const& msg)
|
||||||
: msg_(msg)
|
: msg_(msg)
|
||||||
, future_use_(NULL)
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
Exception::~Exception() throw()
|
Exception::~Exception() throw()
|
||||||
{}
|
{}
|
||||||
char const* Exception::what() const throw()
|
char const* Exception::what() const throw()
|
||||||
{
|
{
|
||||||
return msg_.c_str();
|
return msg_.c_str();
|
||||||
}
|
}
|
||||||
|
RuntimeError::RuntimeError(std::string const& msg)
|
||||||
|
: Exception(msg)
|
||||||
|
{}
|
||||||
|
LogicError::LogicError(std::string const& msg)
|
||||||
|
: Exception(msg)
|
||||||
|
{}
|
||||||
|
void throwRuntimeError(std::string const& msg)
|
||||||
|
{
|
||||||
|
throw RuntimeError(msg);
|
||||||
|
}
|
||||||
|
void throwLogicError(std::string const& msg)
|
||||||
|
{
|
||||||
|
throw LogicError(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user