diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-02-25 00:39:01 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-02-25 00:39:01 +0000 |
| commit | d4b350cc524543b8142ac803232b31af751885e2 (patch) | |
| tree | 45a79c6053f536596a9712c7ae01660f7df6563d /src | |
| parent | 95c6dd4301da219834a7c60fec3fa92c1ec23265 (diff) | |
Throw exceptions with badly-formed XML when reading a DCP; preserve detail in DCPReadError.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp.cc | 2 | ||||
| -rw-r--r-- | src/exceptions.cc | 8 | ||||
| -rw-r--r-- | src/exceptions.h | 19 |
3 files changed, 26 insertions, 3 deletions
@@ -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 |
