From 0c464b24ad7adc8257a54cdc7db9f112104a6c6c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 28 Oct 2016 21:11:52 +0200 Subject: [PATCH] OutputInit: allow "init" to throw exception --- src/output/Internal.hxx | 3 +++ src/output/MultipleOutputs.cxx | 11 ++++++++++- src/output/OutputPlugin.hxx | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index d9958f03f..da6a1bc5c 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -454,6 +454,9 @@ private: */ extern struct notify audio_output_client_notify; +/** + * Throws #std::runtime_error on error. + */ AudioOutput * audio_output_new(EventLoop &event_loop, const ConfigBlock &block, MixerListener &mixer_listener, diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index b168bec84..4251d8237 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -32,6 +32,8 @@ #include "config/ConfigOption.hxx" #include "notify.hxx" +#include + #include #include @@ -51,7 +53,7 @@ MultipleOutputs::~MultipleOutputs() static AudioOutput * LoadOutput(EventLoop &event_loop, MixerListener &mixer_listener, PlayerControl &pc, const ConfigBlock &block) -{ +try { Error error; AudioOutput *output = audio_output_new(event_loop, block, mixer_listener, @@ -66,6 +68,13 @@ LoadOutput(EventLoop &event_loop, MixerListener &mixer_listener, } return output; +} catch (const std::runtime_error &e) { + if (block.line > 0) + FormatFatalError("line %i: %s", + block.line, + e.what()); + else + FatalError(e.what()); } void diff --git a/src/output/OutputPlugin.hxx b/src/output/OutputPlugin.hxx index 5c6d953a9..5f642cce0 100644 --- a/src/output/OutputPlugin.hxx +++ b/src/output/OutputPlugin.hxx @@ -50,6 +50,8 @@ struct AudioOutputPlugin { * Configure and initialize the device, but do not open it * yet. * + * Throws #std::runtime_error on error. + * * @param param the configuration section, or nullptr if there is * no configuration * @return nullptr on error, or an opaque pointer to the plugin's