Commit 6eb9d7e6 authored by Francis Dupont's avatar Francis Dupont

[3697] added a throwTypeError macro to display position

parent 8ab6d170
// Copyright (C) 2010, 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2010, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -136,57 +136,57 @@ Element::setValue(const std::map<std::string, ConstElementPtr>&) {
ConstElementPtr
Element::get(const int) const {
isc_throw(TypeError, "get(int) called on a non-list Element");
throwTypeError("get(int) called on a non-list Element");
}
void
Element::set(const size_t, ConstElementPtr) {
isc_throw(TypeError, "set(int, element) called on a non-list Element");
throwTypeError("set(int, element) called on a non-list Element");
}
void
Element::add(ConstElementPtr) {
isc_throw(TypeError, "add() called on a non-list Element");
throwTypeError("add() called on a non-list Element");
}
void
Element::remove(const int) {
isc_throw(TypeError, "remove(int) called on a non-list Element");
throwTypeError("remove(int) called on a non-list Element");
}
size_t
Element::size() const {
isc_throw(TypeError, "size() called on a non-list Element");
throwTypeError("size() called on a non-list Element");
}
bool
Element::empty() const {
isc_throw(TypeError, "empty() called on a non-list Element");
throwTypeError("empty() called on a non-list Element");
}
ConstElementPtr
Element::get(const std::string&) const {
isc_throw(TypeError, "get(string) called on a non-map Element");
throwTypeError("get(string) called on a non-map Element");
}
void
Element::set(const std::string&, ConstElementPtr) {
isc_throw(TypeError, "set(name, element) called on a non-map Element");
throwTypeError("set(name, element) called on a non-map Element");
}
void
Element::remove(const std::string&) {
isc_throw(TypeError, "remove(string) called on a non-map Element");
throwTypeError("remove(string) called on a non-map Element");
}
bool
Element::contains(const std::string&) const {
isc_throw(TypeError, "contains(string) called on a non-map Element");
throwTypeError("contains(string) called on a non-map Element");
}
ConstElementPtr
Element::find(const std::string&) const {
isc_throw(TypeError, "find(string) called on a non-map Element");
throwTypeError("find(string) called on a non-map Element");
}
bool
......
// Copyright (C) 2010, 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2010, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -186,6 +186,19 @@ public:
std::string toWire() const;
void toWire(std::ostream& out) const;
/// \brief Add the position to a TypeError message
/// should be used in place of isc_throw(TypeError, error)
#define throwTypeError(error) \
{ \
std::string msg_ = error; \
if ((position_.file_ != "") || \
(position_.line_ != 0) || \
(position_.pos_ != 0)) { \
msg_ += " in " + position_.str(); \
} \
isc_throw(TypeError, msg_); \
}
/// \name pure virtuals, every derived class must implement these
/// \return true if the other ElementPtr has the same type and value
......@@ -204,20 +217,20 @@ public:
/// getValue() below
//@{
virtual int64_t intValue() const
{ isc_throw(TypeError, "intValue() called on non-integer Element"); };
{ throwTypeError("intValue() called on non-integer Element"); };
virtual double doubleValue() const
{ isc_throw(TypeError, "doubleValue() called on non-double Element"); };
{ throwTypeError("doubleValue() called on non-double Element"); };
virtual bool boolValue() const
{ isc_throw(TypeError, "boolValue() called on non-Bool Element"); };
{ throwTypeError("boolValue() called on non-Bool Element"); };
virtual std::string stringValue() const
{ isc_throw(TypeError, "stringValue() called on non-string Element"); };
{ throwTypeError("stringValue() called on non-string Element"); };
virtual const std::vector<ConstElementPtr>& listValue() const {
// replace with real exception or empty vector?
isc_throw(TypeError, "listValue() called on non-list Element");
throwTypeError("listValue() called on non-list Element");
};
virtual const std::map<std::string, ConstElementPtr>& mapValue() const {
// replace with real exception or empty map?
isc_throw(TypeError, "mapValue() called on non-map Element");
throwTypeError("mapValue() called on non-map Element");
};
//@}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment