summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-03-15 16:27:50 +0000
committerCarl Hetherington <cth@carlh.net>2019-03-15 16:27:50 +0000
commit5ee64b29d9377944e36451dcf8802fdc04f23f3c (patch)
tree5f4f61f6a5ca2549da1794ba521c0421f32bb86c /src
parent80e45e33e2c5dd6bfc4484f3fb05c02d13854b8d (diff)
Give better errors on malformed subrip times.
Diffstat (limited to 'src')
-rw-r--r--src/subrip_reader.cc33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc
index 16ba0a5..cf0b86f 100644
--- a/src/subrip_reader.cc
+++ b/src/subrip_reader.cc
@@ -158,12 +158,33 @@ SubripReader::convert_time (string t)
throw SubripError (t, "time in the format h:m:s,ms", _context);
}
- return Time::from_hms (
- lexical_cast<int> (a[0]),
- lexical_cast<int> (a[1]),
- lexical_cast<int> (b[0]),
- lexical_cast<int> (b[1])
- );
+ int h, m, s, ms;
+
+ try {
+ h = lexical_cast<int>(a[0]);
+ } catch (boost::bad_lexical_cast &) {
+ throw SubripError (t, "integer hour value", _context);
+ }
+
+ try {
+ m = lexical_cast<int>(a[1]);
+ } catch (boost::bad_lexical_cast &) {
+ throw SubripError (t, "integer minute value", _context);
+ }
+
+ try {
+ s = lexical_cast<int>(b[0]);
+ } catch (boost::bad_lexical_cast &) {
+ throw SubripError (t, "integer second value", _context);
+ }
+
+ try {
+ ms = lexical_cast<int>(b[1]);
+ } catch (boost::bad_lexical_cast &) {
+ throw SubripError (t, "integer millisecond value", _context);
+ }
+
+ return Time::from_hms (h, m, s, ms);
}
void