Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
b20e0a5e
Commit
b20e0a5e
authored
May 14, 2012
by
beder
Browse files
Switched all new API runtime_error exceptions to exceptions that derive from YAML::Exception
parent
cfb7d462
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
9 deletions
+38
-9
include/yaml-cpp/exceptions.h
include/yaml-cpp/exceptions.h
+28
-0
include/yaml-cpp/node/detail/impl.h
include/yaml-cpp/node/detail/impl.h
+2
-2
include/yaml-cpp/node/impl.h
include/yaml-cpp/node/impl.h
+4
-3
src/node_data.cpp
src/node_data.cpp
+4
-4
No files found.
include/yaml-cpp/exceptions.h
View file @
b20e0a5e
...
@@ -57,7 +57,10 @@ namespace YAML
...
@@ -57,7 +57,10 @@ namespace YAML
const
char
*
const
INVALID_SCALAR
=
"invalid scalar"
;
const
char
*
const
INVALID_SCALAR
=
"invalid scalar"
;
const
char
*
const
KEY_NOT_FOUND
=
"key not found"
;
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_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
UNMATCHED_GROUP_TAG
=
"unmatched group tag"
;
const
char
*
const
UNEXPECTED_END_SEQ
=
"unexpected end sequence token"
;
const
char
*
const
UNEXPECTED_END_SEQ
=
"unexpected end sequence token"
;
...
@@ -148,11 +151,36 @@ namespace YAML
...
@@ -148,11 +151,36 @@ namespace YAML
return
TypedKeyNotFound
<
T
>
(
mark
,
key
);
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
{
class
BadDereference
:
public
RepresentationException
{
public:
public:
BadDereference
()
BadDereference
()
:
RepresentationException
(
Mark
::
null
(),
ErrorMsg
::
BAD_DEREFERENCE
)
{}
:
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
{
class
EmitterException
:
public
Exception
{
public:
public:
...
...
include/yaml-cpp/node/detail/impl.h
View file @
b20e0a5e
...
@@ -61,7 +61,7 @@ namespace YAML
...
@@ -61,7 +61,7 @@ namespace YAML
return
*
pNode
;
return
*
pNode
;
return
pMemory
->
create_node
();
return
pMemory
->
create_node
();
case
NodeType
::
Scalar
:
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
)
{
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
...
@@ -89,7 +89,7 @@ namespace YAML
...
@@ -89,7 +89,7 @@ namespace YAML
convert_to_map
(
pMemory
);
convert_to_map
(
pMemory
);
break
;
break
;
case
NodeType
::
Scalar
:
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
)
{
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
...
...
include/yaml-cpp/node/impl.h
View file @
b20e0a5e
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/iterator.h"
#include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/exceptions.h"
#include <string>
#include <string>
namespace
YAML
namespace
YAML
...
@@ -102,12 +103,12 @@ namespace YAML
...
@@ -102,12 +103,12 @@ namespace YAML
const
T
operator
()()
const
{
const
T
operator
()()
const
{
if
(
!
node
.
m_pNode
)
if
(
!
node
.
m_pNode
)
throw
std
::
runtime_error
(
"Unable to convert to type"
);
throw
TypedBadConversion
<
T
>
(
);
T
t
;
T
t
;
if
(
convert
<
T
>::
decode
(
node
,
t
))
if
(
convert
<
T
>::
decode
(
node
,
t
))
return
t
;
return
t
;
throw
std
::
runtime_error
(
"Unable to convert to type"
);
throw
TypedBadConversion
<
T
>
(
);
}
}
};
};
...
@@ -118,7 +119,7 @@ namespace YAML
...
@@ -118,7 +119,7 @@ namespace YAML
const
std
::
string
operator
()()
const
{
const
std
::
string
operator
()()
const
{
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
if
(
node
.
Type
()
!=
NodeType
::
Scalar
)
throw
std
::
runtime_error
(
"Unable to convert to string, not a scalar"
);
throw
TypedBadConversion
<
std
::
string
>
(
);
return
node
.
Scalar
();
return
node
.
Scalar
();
}
}
};
};
...
...
src/node_data.cpp
View file @
b20e0a5e
#include "yaml-cpp/node/detail/node_data.h"
#include "yaml-cpp/node/detail/node_data.h"
#include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/memory.h"
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/node/detail/node.h"
#include "yaml-cpp/exceptions.h"
#include <sstream>
#include <sstream>
#include <stdexcept>
namespace
YAML
namespace
YAML
{
{
...
@@ -161,7 +161,7 @@ namespace YAML
...
@@ -161,7 +161,7 @@ namespace YAML
}
}
if
(
m_type
!=
NodeType
::
Sequence
)
if
(
m_type
!=
NodeType
::
Sequence
)
throw
std
::
runtime_error
(
"Can't p
ush
_
back
to a non-sequence node"
);
throw
BadP
ushback
(
);
m_sequence
.
push_back
(
&
node
);
m_sequence
.
push_back
(
&
node
);
}
}
...
@@ -177,7 +177,7 @@ namespace YAML
...
@@ -177,7 +177,7 @@ namespace YAML
convert_to_map
(
pMemory
);
convert_to_map
(
pMemory
);
break
;
break
;
case
NodeType
::
Scalar
:
case
NodeType
::
Scalar
:
throw
std
::
runtime_error
(
"Can't call operator[] on a scalar"
);
throw
BadSubscript
(
);
}
}
insert_map_pair
(
key
,
value
);
insert_map_pair
(
key
,
value
);
...
@@ -208,7 +208,7 @@ namespace YAML
...
@@ -208,7 +208,7 @@ namespace YAML
convert_to_map
(
pMemory
);
convert_to_map
(
pMemory
);
break
;
break
;
case
NodeType
::
Scalar
:
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
)
{
for
(
node_map
::
const_iterator
it
=
m_map
.
begin
();
it
!=
m_map
.
end
();
++
it
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment