summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-02-25 00:39:01 +0000
committerCarl Hetherington <cth@carlh.net>2018-02-25 00:39:01 +0000
commitd4b350cc524543b8142ac803232b31af751885e2 (patch)
tree45a79c6053f536596a9712c7ae01660f7df6563d /src
parent95c6dd4301da219834a7c60fec3fa92c1ec23265 (diff)
Throw exceptions with badly-formed XML when reading a DCP; preserve detail in DCPReadError.
Diffstat (limited to 'src')
-rw-r--r--src/dcp.cc2
-rw-r--r--src/exceptions.cc8
-rw-r--r--src/exceptions.h19
3 files changed, 26 insertions, 3 deletions
diff --git a/src/dcp.cc b/src/dcp.cc
index fc02fe9d..7b4f9bda 100644
--- a/src/dcp.cc
+++ b/src/dcp.cc
@@ -169,7 +169,7 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx
p->parse_file (path.string());
} catch (std::exception& e) {
delete p;
- continue;
+ throw DCPReadError(String::compose("XML error in %1", path.string()), e.what());
}
string const root = p->get_document()->get_root_node()->get_name ();
diff --git a/src/exceptions.cc b/src/exceptions.cc
index 71771b1c..1ded4483 100644
--- a/src/exceptions.cc
+++ b/src/exceptions.cc
@@ -108,3 +108,11 @@ CertificateChainError::CertificateChainError (std::string message)
{
}
+
+DCPReadError::DCPReadError (string message, string detail)
+ : runtime_error(String::compose("%1 (%2)", message, detail))
+ , _message(message)
+ , _detail(detail)
+{
+
+}
diff --git a/src/exceptions.h b/src/exceptions.h
index f187df1c..3d80b635 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -35,6 +35,7 @@
#define LIBDCP_EXCEPTIONS_H
#include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
/** @file src/exceptions.h
* @brief Exceptions thrown by libdcp.
@@ -97,8 +98,22 @@ class DCPReadError : public std::runtime_error
{
public:
explicit DCPReadError (std::string message)
- : std::runtime_error (message)
+ : std::runtime_error(message)
{}
+
+ DCPReadError (std::string message, std::string detail);
+
+ std::string message () const {
+ return _message;
+ }
+
+ boost::optional<std::string> detail () const {
+ return _detail;
+ }
+
+private:
+ std::string _message;
+ boost::optional<std::string> _detail;
};
/** @class MissingAssetError