diff --git a/src/decoder/plugins/FlacCommon.cxx b/src/decoder/plugins/FlacCommon.cxx index 33f728a67..fbc336f3a 100644 --- a/src/decoder/plugins/FlacCommon.cxx +++ b/src/decoder/plugins/FlacCommon.cxx @@ -24,10 +24,11 @@ #include "config.h" #include "FlacCommon.hxx" #include "FlacMetadata.hxx" -#include "util/Error.hxx" #include "util/ConstBuffer.hxx" #include "Log.hxx" +#include + bool FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample, unsigned channels, FLAC__uint64 total_frames) @@ -35,10 +36,11 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample, assert(!initialized); assert(!unsupported); - ::Error error; - if (!pcm_import.Open(sample_rate, bits_per_sample, - channels, error)) { - LogError(error); + try { + pcm_import.Open(sample_rate, bits_per_sample, + channels); + } catch (const std::runtime_error &e) { + LogError(e); unsupported = true; return false; } diff --git a/src/decoder/plugins/FlacDecoderPlugin.cxx b/src/decoder/plugins/FlacDecoderPlugin.cxx index 2b9d7bb72..955d41360 100644 --- a/src/decoder/plugins/FlacDecoderPlugin.cxx +++ b/src/decoder/plugins/FlacDecoderPlugin.cxx @@ -26,7 +26,6 @@ #include "OggCodec.hxx" #include "fs/Path.hxx" #include "fs/NarrowPath.hxx" -#include "util/Error.hxx" #include "Log.hxx" #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 diff --git a/src/decoder/plugins/FlacPcm.cxx b/src/decoder/plugins/FlacPcm.cxx index 82d2dadf4..f18774cde 100644 --- a/src/decoder/plugins/FlacPcm.cxx +++ b/src/decoder/plugins/FlacPcm.cxx @@ -19,9 +19,8 @@ #include "config.h" #include "FlacPcm.hxx" -#include "FlacDomain.hxx" #include "CheckAudioFormat.hxx" -#include "util/Error.hxx" +#include "util/RuntimeError.hxx" #include "util/ConstBuffer.hxx" #include @@ -47,19 +46,16 @@ flac_sample_format(unsigned bits_per_sample) } } -bool +void FlacPcmImport::Open(unsigned sample_rate, unsigned bits_per_sample, - unsigned channels, Error &error) + unsigned channels) { auto sample_format = flac_sample_format(bits_per_sample); - if (sample_format == SampleFormat::UNDEFINED) { - error.Format(flac_domain, "Unsupported FLAC bit depth: %u", - bits_per_sample); - return false; - } + if (sample_format == SampleFormat::UNDEFINED) + throw FormatRuntimeError("Unsupported FLAC bit depth: %u", + bits_per_sample); audio_format = CheckAudioFormat(sample_rate, sample_format, channels); - return true; } template diff --git a/src/decoder/plugins/FlacPcm.hxx b/src/decoder/plugins/FlacPcm.hxx index 9c6641025..4aa13df5f 100644 --- a/src/decoder/plugins/FlacPcm.hxx +++ b/src/decoder/plugins/FlacPcm.hxx @@ -26,7 +26,6 @@ #include -class Error; template struct ConstBuffer; /** @@ -39,8 +38,11 @@ class FlacPcmImport { AudioFormat audio_format; public: - bool Open(unsigned sample_rate, unsigned bits_per_sample, - unsigned channels, Error &error); + /** + * Throws #std::runtime_error on error. + */ + void Open(unsigned sample_rate, unsigned bits_per_sample, + unsigned channels); const AudioFormat &GetAudioFormat() const { return audio_format;