Main, ...: catch any exception, not just std::runtime_error

This commit is contained in:
Max Kellermann
2017-12-19 10:56:23 +01:00
parent a539094c06
commit 914df18bf9
79 changed files with 236 additions and 244 deletions
+3 -2
View File
@@ -205,8 +205,9 @@ AudioOutputControl::Open(const AudioFormat audio_format,
if (open2 && output->mixer != nullptr) {
try {
mixer_open(output->mixer);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to open mixer for '%s'",
} catch (...) {
FormatError(std::current_exception(),
"Failed to open mixer for '%s'",
GetName());
}
}
+7 -7
View File
@@ -45,7 +45,7 @@ FilteredAudioOutput::Enable()
{
try {
output->Enable();
} catch (const std::runtime_error &e) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to enable output %s",
GetLogName()));
}
@@ -62,7 +62,7 @@ FilteredAudioOutput::ConfigureConvertFilter()
{
try {
convert_filter_set(convert_filter.Get(), out_audio_format);
} catch (const std::runtime_error &e) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to convert for %s",
GetLogName()));
}
@@ -75,7 +75,7 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
try {
output->Open(out_audio_format);
} catch (const std::runtime_error &e) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to open %s",
GetLogName()));
}
@@ -87,7 +87,7 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
try {
ConfigureConvertFilter();
} catch (const std::runtime_error &e) {
} catch (...) {
output->Close();
if (out_audio_format.format == SampleFormat::DSD) {
@@ -97,7 +97,7 @@ FilteredAudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
implemented; our last resort is to give up
DSD and fall back to PCM */
LogError(e);
LogError(std::current_exception());
FormatError(output_domain, "Retrying without DSD");
desired_audio_format.format = SampleFormat::FLOAT;
@@ -184,8 +184,8 @@ FilteredAudioOutput::IteratePause() noexcept
{
try {
return output->Pause();
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to pause %s",
} catch (...) {
FormatError(std::current_exception(), "Failed to pause %s",
GetLogName());
return false;
}
+4 -4
View File
@@ -186,11 +186,11 @@ FilteredAudioOutput::Configure(const ConfigBlock &block)
try {
filter_chain_parse(*prepared_filter,
block.GetBlockValue(AUDIO_FILTERS, ""));
} catch (const std::runtime_error &e) {
} catch (...) {
/* It's not really fatal - Part of the filter chain
has been set up already and even an empty one will
work (if only with unexpected behaviour) */
FormatError(e,
FormatError(std::current_exception(),
"Failed to initialize filter chain for '%s'",
name);
}
@@ -232,8 +232,8 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
mixer_plugin,
*prepared_filter,
mixer_listener);
} catch (const std::runtime_error &e) {
FormatError(e,
} catch (...) {
FormatError(std::current_exception(),
"Failed to initialize hardware mixer for '%s'",
name);
}
+1 -1
View File
@@ -57,7 +57,7 @@ LoadOutput(EventLoop &event_loop,
try {
return audio_output_new(event_loop, replay_gain_config, block,
mixer_listener);
} catch (const std::runtime_error &e) {
} catch (...) {
if (block.line > 0)
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i",
block.line));
+17 -14
View File
@@ -72,7 +72,7 @@ AudioOutputControl::InternalOpen2(const AudioFormat in_audio_format)
try {
output->ConfigureConvertFilter();
} catch (const std::runtime_error &e) {
} catch (...) {
open = false;
{
@@ -107,8 +107,8 @@ AudioOutputControl::InternalEnable() noexcept
really_enabled = true;
return true;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
fail_timer.Update();
last_error = std::current_exception();
return false;
@@ -149,7 +149,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
output->prepared_replay_gain_filter,
output->prepared_other_replay_gain_filter,
output->prepared_filter);
} catch (const std::runtime_error &e) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to open filter for %s",
GetLogName()));
}
@@ -160,8 +160,8 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
source.Close();
throw;
}
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
fail_timer.Update();
last_error = std::current_exception();
}
@@ -231,8 +231,9 @@ bool
AudioOutputControl::FillSourceOrClose()
try {
return source.Fill(mutex);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to filter for %s", GetLogName());
} catch (...) {
FormatError(std::current_exception(),
"Failed to filter for %s", GetLogName());
InternalClose(false);
@@ -251,8 +252,9 @@ AudioOutputControl::PlayChunk() noexcept
const ScopeUnlock unlock(mutex);
try {
output->SendTag(*tag);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to send tag to %s",
} catch (...) {
FormatError(std::current_exception(),
"Failed to send tag to %s",
GetLogName());
}
}
@@ -273,8 +275,9 @@ AudioOutputControl::PlayChunk() noexcept
const ScopeUnlock unlock(mutex);
nbytes = output->Play(data.data, data.size);
assert(nbytes <= data.size);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to play on %s", GetLogName());
} catch (...) {
FormatError(std::current_exception(),
"Failed to play on %s", GetLogName());
nbytes = 0;
}
@@ -382,8 +385,8 @@ AudioOutputControl::Task()
try {
SetThreadRealtime();
} catch (const std::runtime_error &e) {
LogError(e,
} catch (...) {
LogError(std::current_exception(),
"OutputThread could not get realtime scheduling, continuing anyway");
}
+1 -1
View File
@@ -875,7 +875,7 @@ try {
call */
return;
}
} catch (const std::runtime_error &) {
} catch (...) {
MultiSocketMonitor::Reset();
LockCaughtError();
}
+2 -2
View File
@@ -92,8 +92,8 @@ FifoOutput::Delete()
try {
RemoveFile(path);
} catch (const std::runtime_error &e) {
LogError(e, "Could not remove FIFO");
} catch (...) {
LogError(std::current_exception(), "Could not remove FIFO");
return;
}
+1 -1
View File
@@ -856,7 +856,7 @@ try {
PulseOutput po(empty);
po.WaitConnection();
return true;
} catch (const std::runtime_error &e) {
} catch (...) {
return false;
}
+11 -11
View File
@@ -154,7 +154,7 @@ RecorderOutput::Open(AudioFormat &audio_format)
try {
encoder = prepared_encoder->Open(audio_format);
} catch (const std::runtime_error &) {
} catch (...) {
delete file;
throw;
}
@@ -162,7 +162,7 @@ RecorderOutput::Open(AudioFormat &audio_format)
if (!HasDynamicPath()) {
try {
EncoderToFile();
} catch (const std::runtime_error &) {
} catch (...) {
delete encoder;
throw;
}
@@ -218,8 +218,8 @@ RecorderOutput::Close() noexcept
try {
Commit();
} catch (const std::exception &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
}
if (HasDynamicPath()) {
@@ -238,8 +238,8 @@ RecorderOutput::FinishFormat()
try {
Commit();
} catch (const std::exception &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
}
file = nullptr;
@@ -270,7 +270,7 @@ RecorderOutput::ReopenFormat(AllocatedPath &&new_path)
try {
EncoderToOutputStream(*new_file, *encoder);
} catch (const std::exception &e) {
} catch (...) {
delete encoder;
delete new_file;
throw;
@@ -302,8 +302,8 @@ RecorderOutput::SendTag(const Tag &tag)
try {
new_path = ParsePath(p);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
FinishFormat();
return;
}
@@ -313,8 +313,8 @@ RecorderOutput::SendTag(const Tag &tag)
try {
ReopenFormat(std::move(new_path));
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
}
+1 -1
View File
@@ -251,7 +251,7 @@ ShoutOutput::Close() noexcept
try {
encoder->End();
WritePage();
} catch (const std::runtime_error &) {
} catch (...) {
/* ignore */
}
@@ -179,7 +179,7 @@ HttpdOutput::ReadPage()
buffer underruns */
try {
encoder->Flush();
} catch (const std::runtime_error &) {
} catch (...) {
/* ignore */
}
@@ -376,7 +376,7 @@ HttpdOutput::SendTag(const Tag &tag)
try {
encoder->PreTag();
} catch (const std::runtime_error &) {
} catch (...) {
/* ignore */
}
@@ -388,7 +388,7 @@ HttpdOutput::SendTag(const Tag &tag)
try {
encoder->SendTag(tag);
encoder->Flush();
} catch (const std::runtime_error &) {
} catch (...) {
/* ignore */
}