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
0c772c4c
Commit
0c772c4c
authored
Nov 08, 2012
by
Jesse Beder
Browse files
Set LoadFile and LoadAllFromFile to throw an exception if we can't load the file
parent
a03e861d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
0 deletions
+10
-0
include/yaml-cpp/exceptions.h
include/yaml-cpp/exceptions.h
+6
-0
src/parse.cpp
src/parse.cpp
+4
-0
No files found.
include/yaml-cpp/exceptions.h
View file @
0c772c4c
...
@@ -70,6 +70,7 @@ namespace YAML
...
@@ -70,6 +70,7 @@ namespace YAML
const
char
*
const
INVALID_ANCHOR
=
"invalid anchor"
;
const
char
*
const
INVALID_ANCHOR
=
"invalid anchor"
;
const
char
*
const
INVALID_ALIAS
=
"invalid alias"
;
const
char
*
const
INVALID_ALIAS
=
"invalid alias"
;
const
char
*
const
INVALID_TAG
=
"invalid tag"
;
const
char
*
const
INVALID_TAG
=
"invalid tag"
;
const
char
*
const
BAD_FILE
=
"bad file"
;
template
<
typename
T
>
template
<
typename
T
>
inline
const
std
::
string
KEY_NOT_FOUND_WITH_KEY
(
const
T
&
,
typename
disable_if
<
is_numeric
<
T
>
>::
type
*
=
0
)
{
inline
const
std
::
string
KEY_NOT_FOUND_WITH_KEY
(
const
T
&
,
typename
disable_if
<
is_numeric
<
T
>
>::
type
*
=
0
)
{
...
@@ -190,6 +191,11 @@ namespace YAML
...
@@ -190,6 +191,11 @@ namespace YAML
EmitterException
(
const
std
::
string
&
msg_
)
EmitterException
(
const
std
::
string
&
msg_
)
:
Exception
(
Mark
::
null
(),
msg_
)
{}
:
Exception
(
Mark
::
null
(),
msg_
)
{}
};
};
class
BadFile
:
public
Exception
{
public:
BadFile
()
:
Exception
(
Mark
::
null
(),
ErrorMsg
::
BAD_FILE
)
{}
};
}
}
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
src/parse.cpp
View file @
0c772c4c
...
@@ -30,6 +30,8 @@ namespace YAML
...
@@ -30,6 +30,8 @@ namespace YAML
Node
LoadFile
(
const
std
::
string
&
filename
)
{
Node
LoadFile
(
const
std
::
string
&
filename
)
{
std
::
ifstream
fin
(
filename
.
c_str
());
std
::
ifstream
fin
(
filename
.
c_str
());
if
(
!
fin
)
throw
BadFile
();
return
Load
(
fin
);
return
Load
(
fin
);
}
}
...
@@ -59,6 +61,8 @@ namespace YAML
...
@@ -59,6 +61,8 @@ namespace YAML
std
::
vector
<
Node
>
LoadAllFromFile
(
const
std
::
string
&
filename
)
{
std
::
vector
<
Node
>
LoadAllFromFile
(
const
std
::
string
&
filename
)
{
std
::
ifstream
fin
(
filename
.
c_str
());
std
::
ifstream
fin
(
filename
.
c_str
());
if
(
!
fin
)
throw
BadFile
();
return
LoadAll
(
fin
);
return
LoadAll
(
fin
);
}
}
}
}
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