diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-18 00:40:20 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-18 00:40:20 +0100 |
| commit | 072e2bc8edab836217f4986c5dd9a95f483fd157 (patch) | |
| tree | 80c01824a196f896c6c346552d6e1b5e08240bad /src | |
| parent | dfd9622f157f1e778352e418eec53483af7ba724 (diff) | |
Use our own exceptions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/exceptions.h | 64 | ||||
| -rw-r--r-- | src/picture_asset.cc | 15 | ||||
| -rw-r--r-- | src/sound_asset.cc | 15 | ||||
| -rw-r--r-- | src/util.cc | 5 | ||||
| -rw-r--r-- | src/wscript | 1 |
5 files changed, 82 insertions, 18 deletions
diff --git a/src/exceptions.h b/src/exceptions.h new file mode 100644 index 00000000..0dbbec4b --- /dev/null +++ b/src/exceptions.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/exceptions.h + * @brief Exceptions thrown by libdcp. + */ + +namespace libdcp +{ + +class FileError : public std::exception +{ +public: + FileError (std::string const & message, std::string const & filename) + : _message (message) + , _filename (filename) + {} + + ~FileError () throw () {} + + char const * what () const throw () { + return _message.c_str (); + } + + std::string filename () const { + return _filename; + } + +private: + std::string _message; + std::string _filename; +}; + +class MiscError : public std::exception +{ +public: + MiscError (std::string const & message) : _message (message) {} + ~MiscError () throw () {} + + char const * what () const throw () { + return _message.c_str (); + } + +private: + std::string _message; +}; + +} diff --git a/src/picture_asset.cc b/src/picture_asset.cc index 383d218a..1620a1fa 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -30,6 +30,7 @@ #include "KM_fileio.h" #include "picture_asset.h" #include "util.h" +#include "exceptions.h" using namespace std; using namespace boost; @@ -77,9 +78,7 @@ PictureAsset::construct (sigc::slot<string, int> get_path) ASDCP::JP2K::CodestreamParser j2k_parser; ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte); if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) { - stringstream s; - s << "could not open " << get_path(0) << " for reading"; - throw runtime_error (s.str()); + throw FileError ("could not open JPEG2000 file for reading", get_path (0)); } ASDCP::JP2K::PictureDescriptor picture_desc; @@ -91,7 +90,7 @@ PictureAsset::construct (sigc::slot<string, int> get_path) ASDCP::JP2K::MXFWriter mxf_writer; if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, picture_desc))) { - throw runtime_error ("could not open MXF for writing"); + throw FileError ("could not open MXF file for writing", _mxf_path); } for (int i = 0; i < _length; ++i) { @@ -99,21 +98,19 @@ PictureAsset::construct (sigc::slot<string, int> get_path) string const path = get_path (i); if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) { - stringstream s; - s << "could not open " << path << " for reading"; - throw runtime_error (s.str()); + throw FileError ("could not open JPEG2000 file for reading", path); } /* XXX: passing 0 to WriteFrame ok? */ if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) { - throw runtime_error ("error in writing video MXF"); + throw MiscError ("error in writing video MXF"); } (*_progress) (0.5 * float (i) / _length); } if (ASDCP_FAILURE (mxf_writer.Finalize())) { - throw runtime_error ("error in finalising video MXF"); + throw MiscError ("error in finalising video MXF"); } _digest = make_digest (_mxf_path, _progress); diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 0d32db2a..d2c451fb 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -27,6 +27,7 @@ #include "AS_DCP.h" #include "sound_asset.h" #include "util.h" +#include "exceptions.h" using namespace std; using namespace boost; @@ -65,7 +66,7 @@ SoundAsset::construct (sigc::slot<string, Channel> get_path) ASDCP::PCM::WAVParser pcm_parser_channel[_channels]; if (pcm_parser_channel[0].OpenRead (get_path(LEFT).c_str(), asdcp_fps)) { - throw runtime_error ("could not open WAV file for reading"); + throw FileError ("could not open WAV file for reading", get_path(LEFT)); } ASDCP::PCM::AudioDescriptor audio_desc; @@ -92,7 +93,7 @@ SoundAsset::construct (sigc::slot<string, Channel> get_path) string const path = get_path (channels[i]); if (ASDCP_FAILURE (pcm_parser_channel[i].OpenRead (path.c_str(), asdcp_fps))) { - throw runtime_error ("could not open WAV file for reading"); + throw FileError ("could not open WAV file for reading", path); } pcm_parser_channel[i].FillAudioDescriptor (audio_desc_channel[i]); @@ -111,7 +112,7 @@ SoundAsset::construct (sigc::slot<string, Channel> get_path) ASDCP::PCM::MXFWriter mxf_writer; if (ASDCP_FAILURE (mxf_writer.OpenWrite (_mxf_path.c_str(), writer_info, audio_desc))) { - throw runtime_error ("could not open audio MXF for writing"); + throw FileError ("could not open audio MXF for writing", _mxf_path); } for (int i = 0; i < _length; ++i) { @@ -124,11 +125,11 @@ SoundAsset::construct (sigc::slot<string, Channel> get_path) for (int j = 0; j < _channels; ++j) { memset (frame_buffer_channel[j].Data(), 0, frame_buffer_channel[j].Capacity()); if (ASDCP_FAILURE (pcm_parser_channel[j].ReadFrame (frame_buffer_channel[j]))) { - throw runtime_error ("could not read audio frame"); + throw MiscError ("could not read audio frame"); } if (frame_buffer_channel[j].Size() != frame_buffer_channel[j].Capacity()) { - throw runtime_error ("short audio frame"); + throw MiscError ("short audio frame"); } } @@ -142,14 +143,14 @@ SoundAsset::construct (sigc::slot<string, Channel> get_path) } if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) { - throw runtime_error ("could not write audio MXF frame"); + throw MiscError ("could not write audio MXF frame"); } (*_progress) (0.5 * float (i) / _length); } if (ASDCP_FAILURE (mxf_writer.Finalize())) { - throw runtime_error ("could not finalise audio MXF"); + throw MiscError ("could not finalise audio MXF"); } _digest = make_digest (_mxf_path, _progress); diff --git a/src/util.cc b/src/util.cc index 2968ef55..849b7d24 100644 --- a/src/util.cc +++ b/src/util.cc @@ -31,6 +31,7 @@ #include "KM_fileio.h" #include "AS_DCP.h" #include "util.h" +#include "exceptions.h" using namespace std; using namespace boost; @@ -52,7 +53,7 @@ libdcp::make_digest (string filename, sigc::signal1<void, float>* progress) Kumu::FileReader reader; if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) { - throw runtime_error ("could not open file to compute digest"); + throw FileError ("could not open file to compute digest", filename); } SHA_CTX sha; @@ -67,7 +68,7 @@ libdcp::make_digest (string filename, sigc::signal1<void, float>* progress) if (r == Kumu::RESULT_ENDOFFILE) { break; } else if (ASDCP_FAILURE (r)) { - throw runtime_error ("could not read file to compute digest"); + throw FileError ("could not read file to compute digest", filename); } SHA1_Update (&sha, read_buffer.Data(), read); diff --git a/src/wscript b/src/wscript index db6906c8..a57bb75b 100644 --- a/src/wscript +++ b/src/wscript @@ -18,6 +18,7 @@ def build(bld): dcp.h metadata.h types.h + exceptions.h """ bld.install_files('${PREFIX}/include/libdcp', headers) |
