mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-08 20:31:17 +00:00
Switched all new API runtime_error exceptions to exceptions that derive from YAML::Exception
This commit is contained in:
@@ -57,7 +57,10 @@ namespace YAML
|
||||
|
||||
const char * const INVALID_SCALAR = "invalid scalar";
|
||||
const char * const KEY_NOT_FOUND = "key not found";
|
||||
const char * const BAD_CONVERSION = "bad conversion";
|
||||
const char * const BAD_DEREFERENCE = "bad dereference";
|
||||
const char * const BAD_SUBSCRIPT = "operator[] call on a scalar";
|
||||
const char * const BAD_PUSHBACK = "appending to a non-sequence";
|
||||
|
||||
const char * const UNMATCHED_GROUP_TAG = "unmatched group tag";
|
||||
const char * const UNEXPECTED_END_SEQ = "unexpected end sequence token";
|
||||
@@ -148,11 +151,36 @@ namespace YAML
|
||||
return TypedKeyNotFound <T> (mark, key);
|
||||
}
|
||||
|
||||
class BadConversion: public RepresentationException {
|
||||
public:
|
||||
BadConversion()
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_CONVERSION) {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class TypedBadConversion: public BadConversion {
|
||||
public:
|
||||
TypedBadConversion()
|
||||
: BadConversion() {}
|
||||
};
|
||||
|
||||
class BadDereference: public RepresentationException {
|
||||
public:
|
||||
BadDereference()
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
|
||||
};
|
||||
|
||||
class BadSubscript: public RepresentationException {
|
||||
public:
|
||||
BadSubscript()
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_SUBSCRIPT) {}
|
||||
};
|
||||
|
||||
class BadPushback: public RepresentationException {
|
||||
public:
|
||||
BadPushback()
|
||||
: RepresentationException(Mark::null(), ErrorMsg::BAD_PUSHBACK) {}
|
||||
};
|
||||
|
||||
class EmitterException: public Exception {
|
||||
public:
|
||||
|
@@ -61,7 +61,7 @@ namespace YAML
|
||||
return *pNode;
|
||||
return pMemory->create_node();
|
||||
case NodeType::Scalar:
|
||||
throw std::runtime_error("Can't call operator[] on a scalar");
|
||||
throw BadSubscript();
|
||||
}
|
||||
|
||||
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
@@ -89,7 +89,7 @@ namespace YAML
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw std::runtime_error("Can't call operator[] on a scalar");
|
||||
throw BadSubscript();
|
||||
}
|
||||
|
||||
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "yaml-cpp/node/iterator.h"
|
||||
#include "yaml-cpp/node/detail/memory.h"
|
||||
#include "yaml-cpp/node/detail/node.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include <string>
|
||||
|
||||
namespace YAML
|
||||
@@ -102,12 +103,12 @@ namespace YAML
|
||||
|
||||
const T operator()() const {
|
||||
if(!node.m_pNode)
|
||||
throw std::runtime_error("Unable to convert to type");
|
||||
throw TypedBadConversion<T>();
|
||||
|
||||
T t;
|
||||
if(convert<T>::decode(node, t))
|
||||
return t;
|
||||
throw std::runtime_error("Unable to convert to type");
|
||||
throw TypedBadConversion<T>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,7 +119,7 @@ namespace YAML
|
||||
|
||||
const std::string operator()() const {
|
||||
if(node.Type() != NodeType::Scalar)
|
||||
throw std::runtime_error("Unable to convert to string, not a scalar");
|
||||
throw TypedBadConversion<std::string>();
|
||||
return node.Scalar();
|
||||
}
|
||||
};
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#include "yaml-cpp/node/detail/node_data.h"
|
||||
#include "yaml-cpp/node/detail/memory.h"
|
||||
#include "yaml-cpp/node/detail/node.h"
|
||||
#include "yaml-cpp/exceptions.h"
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace YAML
|
||||
}
|
||||
|
||||
if(m_type != NodeType::Sequence)
|
||||
throw std::runtime_error("Can't push_back to a non-sequence node");
|
||||
throw BadPushback();
|
||||
|
||||
m_sequence.push_back(&node);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace YAML
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw std::runtime_error("Can't call operator[] on a scalar");
|
||||
throw BadSubscript();
|
||||
}
|
||||
|
||||
insert_map_pair(key, value);
|
||||
@@ -208,7 +208,7 @@ namespace YAML
|
||||
convert_to_map(pMemory);
|
||||
break;
|
||||
case NodeType::Scalar:
|
||||
throw std::runtime_error("Can't call operator[] on a scalar");
|
||||
throw BadSubscript();
|
||||
}
|
||||
|
||||
for(node_map::const_iterator it=m_map.begin();it!=m_map.end();++it) {
|
||||
|
Reference in New Issue
Block a user