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

View File

@ -32,7 +32,7 @@
#endif
#endif
#include <stdexcept>
#include <exception>
Instance::Instance()
:idle_monitor(event_loop, BIND_THIS_METHOD(OnIdle))
@ -84,7 +84,7 @@ Instance::OnDatabaseSongRemoved(const char *uri)
if (sticker_enabled()) {
try {
sticker_song_delete(uri);
} catch (const std::runtime_error &) {
} catch (...) {
}
}
#endif

View File

@ -120,7 +120,7 @@ listen_global_init(EventLoop &loop, Partition &partition)
do {
try {
listen_add_config_param(port, param);
} catch (const std::runtime_error &e) {
} catch (...) {
delete listen_socket;
std::throw_with_nested(FormatRuntimeError("Failed to listen on %s (line %i)",
param->value.c_str(),
@ -133,7 +133,7 @@ listen_global_init(EventLoop &loop, Partition &partition)
try {
listen_socket->AddPort(port);
} catch (const std::runtime_error &e) {
} catch (...) {
delete listen_socket;
std::throw_with_nested(FormatRuntimeError("Failed to listen on *:%d: ", port));
}
@ -141,7 +141,7 @@ listen_global_init(EventLoop &loop, Partition &partition)
try {
listen_socket->Open();
} catch (const std::runtime_error &e) {
} catch (...) {
delete listen_socket;
throw;
}

View File

@ -379,7 +379,7 @@ initialize_decoder_and_player(const ReplayGainConfig &replay_gain_config)
try {
configured_audio_format = ParseAudioFormat(param->value.c_str(),
true);
} catch (const std::runtime_error &) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("error parsing line %i",
param->line));
}

View File

@ -32,7 +32,7 @@
#include "fs/io/BufferedOutputStream.hxx"
#include "util/UriUtil.hxx"
#include <stdexcept>
#include <exception>
static void
playlist_print_path(BufferedOutputStream &os, const Path path)
@ -57,7 +57,7 @@ playlist_print_song(BufferedOutputStream &os, const DetachedSong &song)
try {
const auto uri_fs = AllocatedPath::FromUTF8Throw(uri_utf8);
playlist_print_path(os, uri_fs);
} catch (const std::runtime_error &) {
} catch (...) {
}
}
@ -76,7 +76,7 @@ playlist_print_uri(BufferedOutputStream &os, const char *uri)
if (!path.IsNull())
playlist_print_path(os, path);
} catch (const std::runtime_error &) {
} catch (...) {
}
}

View File

@ -30,7 +30,7 @@
#include "util/UriUtil.hxx"
#include "lib/icu/CaseFold.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <stdlib.h>
@ -190,7 +190,7 @@ ParseTimeStamp(const char *s)
try {
/* try ISO 8601 */
return ParseTimePoint(s, "%FT%TZ");
} catch (const std::runtime_error &) {
} catch (...) {
return std::chrono::system_clock::time_point::min();
}
}

View File

@ -34,7 +34,7 @@
#include "TagArchive.hxx"
#endif
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <string.h>
@ -68,7 +68,7 @@ Song::UpdateFile(Storage &storage)
StorageFileInfo info;
try {
info = storage.GetInfo(relative_uri.c_str(), true);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -77,8 +77,8 @@ stats_update(const Database &db)
stats = db.GetStats(selection);
stats_validity = StatsValidity::VALID;
return true;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
stats_validity = StatsValidity::FAILED;
return false;
}

View File

@ -29,7 +29,7 @@
#include "input/LocalOpen.hxx"
#include "thread/Cond.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
@ -64,13 +64,13 @@ public:
try {
is = OpenLocalInputStream(path_fs,
mutex, cond);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
} else {
try {
is->LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
}

View File

@ -30,7 +30,7 @@
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
@ -66,7 +66,7 @@ tag_stream_scan(InputStream &is, const TagHandler &handler, void *ctx)
&handler, ctx](const DecoderPlugin &plugin){
try {
is.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
return CheckDecoderPlugin(plugin, suffix, mime) &&

View File

@ -68,7 +68,7 @@ handle_listfiles_storage(Response &r, StorageDirectoryReader &reader)
StorageFileInfo info;
try {
info = reader.GetInfo(false);
} catch (const std::runtime_error &) {
} catch (...) {
continue;
}

View File

@ -361,10 +361,10 @@ ProxyDatabase::Open()
try {
Connect();
} catch (const std::runtime_error &error) {
} catch (...) {
/* this error is non-fatal, because this plugin will
attempt to reconnect again automatically */
LogError(error);
LogError(std::current_exception());
}
}
@ -473,8 +473,8 @@ ProxyDatabase::OnSocketReady(gcc_unused unsigned flags) noexcept
if (idle == 0) {
try {
CheckError(connection);
} catch (const std::runtime_error &error) {
LogError(error);
} catch (...) {
LogError(std::current_exception());
Disconnect();
return false;
}
@ -508,8 +508,8 @@ ProxyDatabase::OnIdle() noexcept
if (!mpd_send_idle_mask(connection, MPD_IDLE_DATABASE)) {
try {
ThrowError(connection);
} catch (const std::runtime_error &error) {
LogError(error);
} catch (...) {
LogError(std::current_exception());
}
SocketMonitor::Steal();

View File

@ -34,7 +34,7 @@
#include "Log.hxx"
#include <string>
#include <stdexcept>
#include <exception>
#include <string.h>
@ -153,8 +153,8 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
ArchiveFile *file;
try {
file = archive_file_open(&plugin, path_fs);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
if (directory != nullptr)
editor.LockDeleteDirectory(directory);
return;

View File

@ -119,9 +119,9 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
modified = true;
}
} catch (const std::runtime_error &e) {
} catch (...) {
LogError(std::current_exception());
editor.LockDeleteDirectory(contdir);
LogError(e);
return false;
}

View File

@ -31,7 +31,7 @@
#include "util/StringStrip.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <string.h>
@ -62,8 +62,8 @@ try {
if (!IsFileNotFound(e))
LogError(e);
return false;
} catch (const std::exception &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}
@ -85,7 +85,7 @@ ExcludeList::Check(Path name_fs) const noexcept
try {
if (i.Check(NarrowPath(name_fs).c_str()))
return true;
} catch (const std::runtime_error &) {
} catch (...) {
}
}
#else

View File

@ -187,8 +187,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
FileInfo fi;
try {
fi = FileInfo(child_path_fs);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
continue;
}
@ -198,8 +198,8 @@ recursive_watch_subdirectories(WatchDirectory *directory,
try {
ret = inotify_source->Add(child_path_fs.c_str(),
IN_MASK);
} catch (const std::runtime_error &e) {
FormatError(e,
} catch (...) {
FormatError(std::current_exception(),
"Failed to register %s",
child_path_fs.c_str());
continue;
@ -302,8 +302,8 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update,
inotify_source = new InotifySource(loop,
mpd_inotify_callback,
nullptr);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
@ -312,8 +312,8 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update,
int descriptor;
try {
descriptor = inotify_source->Add(path.c_str(), IN_MASK);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
delete inotify_source;
inotify_source = nullptr;
return;

View File

@ -36,8 +36,8 @@ GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) noexcept
try {
info = storage.GetInfo(uri_utf8, true);
return true;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}
@ -46,8 +46,8 @@ GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) noexcept
try {
info = reader.GetInfo(true);
return true;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}
@ -58,7 +58,7 @@ DirectoryExists(Storage &storage, const Directory &directory) noexcept
try {
info = storage.GetInfo(directory.GetPath(), true);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
@ -83,7 +83,7 @@ directory_child_is_regular(Storage &storage, const Directory &directory,
try {
return GetDirectoryChildInfo(storage, directory, name_utf8)
.IsRegular();
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -338,8 +338,8 @@ UpdateWalk::UpdateDirectory(Directory &directory,
try {
reader.reset(storage.OpenDirectory(directory.GetPath()));
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}

View File

@ -416,7 +416,7 @@ try {
assert(nbytes > 0 || is.IsEOF());
return nbytes;
} catch (const std::runtime_error &e) {
} catch (...) {
error = std::current_exception();
return 0;
}
@ -471,7 +471,7 @@ DecoderBridge::SubmitData(InputStream *is,
auto result = convert->Convert({data, length});
data = result.data;
length = result.size;
} catch (const std::runtime_error &e) {
} catch (...) {
/* the PCM conversion has failed - stop
playback, since we have no better way to
bail out */

View File

@ -37,8 +37,8 @@ decoder_read(DecoderClient *client,
try {
return is.LockRead(buffer, length);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return 0;
}
}

View File

@ -112,7 +112,7 @@ decoder_stream_decode(const DecoderPlugin &plugin,
/* rewind the stream, so each plugin gets a fresh start */
try {
input_stream.Rewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
{

View File

@ -30,7 +30,7 @@
#include <audiofile.h>
#include <af_vfs.h>
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <stdio.h>
@ -120,8 +120,8 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset _offset,
try {
is.LockSeek(offset);
return is.GetOffset();
} catch (const std::runtime_error &e) {
LogError(e, "Seek failed");
} catch (...) {
LogError(std::current_exception(), "Seek failed");
return -1;
}
}

View File

@ -57,7 +57,7 @@ dsdlib_skip_to(DecoderClient *client, InputStream &is,
if (is.IsSeekable()) {
try {
is.LockSeek(offset);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
}
@ -81,7 +81,7 @@ dsdlib_skip(DecoderClient *client, InputStream &is,
if (is.IsSeekable()) {
try {
is.LockSeek(is.GetOffset() + delta);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
}

View File

@ -31,7 +31,7 @@
#include <neaacdec.h>
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <string.h>
@ -196,7 +196,7 @@ faad_song_duration(DecoderBuffer &buffer, InputStream &is)
try {
is.LockSeek(tagsize);
} catch (const std::runtime_error &) {
} catch (...) {
}
buffer.Clear();
@ -316,7 +316,7 @@ faad_get_file_time(InputStream &is)
try {
faad_decoder_init(decoder, buffer, audio_format);
recognized = true;
} catch (const std::runtime_error &e) {
} catch (...) {
}
}

View File

@ -483,7 +483,7 @@ ffmpeg_probe(DecoderClient *client, InputStream &is)
try {
is.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -814,8 +814,8 @@ ffmpeg_decode(DecoderClient &client, InputStream &input)
try {
format_context =FfmpegOpenInput(stream.io, input.GetURI(),
input_format);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
@ -869,7 +869,7 @@ ffmpeg_scan_stream(InputStream &is,
AVFormatContext *f;
try {
f = FfmpegOpenInput(stream.io, is.GetURI(), input_format);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -25,7 +25,7 @@
#include "../DecoderAPI.hxx"
#include "input/InputStream.hxx"
#include <stdexcept>
#include <exception>
AvioStream::~AvioStream()
{
@ -72,7 +72,7 @@ AvioStream::Seek(int64_t pos, int whence)
try {
input.LockSeek(pos);
return input.GetOffset();
} catch (const std::runtime_error &) {
} catch (...) {
return -1;
}
}

View File

@ -27,7 +27,7 @@
#include "util/ConstBuffer.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
bool
FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
@ -39,8 +39,8 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
try {
pcm_import.Open(sample_rate, bits_per_sample,
channels);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
unsupported = true;
return false;
}

View File

@ -330,7 +330,7 @@ oggflac_decode(DecoderClient &client, InputStream &input_stream)
moved it */
try {
input_stream.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
flac_decode_internal(client, input_stream, true);

View File

@ -55,7 +55,7 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
: EINVAL;
return 0;
#endif
} catch (const std::runtime_error &) {
} catch (...) {
/* just some random non-zero errno value */
errno = EINVAL;
return 0;
@ -96,8 +96,8 @@ FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 _offset, int whence)
try {
is->LockSeek(offset);
return 0;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return -1;
}
}

View File

@ -25,7 +25,7 @@
#include "Log.hxx"
#include "Compiler.h"
#include <stdexcept>
#include <exception>
FLAC__StreamDecoderReadStatus
FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
@ -54,8 +54,8 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
try {
input_stream.LockSeek(absolute_byte_offset);
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
}

View File

@ -212,7 +212,7 @@ MadDecoder::Seek(long offset)
{
try {
input_stream.LockSeek(offset);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -32,7 +32,7 @@
#include <mpc/mpcdec.h>
#include <stdexcept>
#include <exception>
#include <math.h>
@ -67,7 +67,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset)
try {
data->is.LockSeek(offset);
return true;
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
}

View File

@ -22,7 +22,7 @@
#include "lib/xiph/OggFind.hxx"
#include "input/InputStream.hxx"
#include <stdexcept>
#include <exception>
/**
* Load the end-of-stream packet and restore the previous file
@ -55,7 +55,7 @@ OggDecoder::LoadEndPacket(ogg_packet &packet) const
/* restore the previous file position */
try {
input_stream.LockSeek(old_offset);
} catch (const std::runtime_error &) {
} catch (...) {
}
return result;

View File

@ -261,7 +261,7 @@ MPDOpusDecoder::Seek(uint64_t where_frame)
try {
SeekGranulePos(where_granulepos);
return true;
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
}
@ -277,7 +277,7 @@ mpd_opus_stream_decode(DecoderClient &client,
moved it */
try {
input_stream.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
DecoderReader reader(client, input_stream);

View File

@ -31,7 +31,7 @@
#include "util/MimeType.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
#include <string.h>
@ -105,8 +105,8 @@ pcm_stream_decode(DecoderClient &client, InputStream &is)
try {
CheckSampleRate(value);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
@ -127,8 +127,8 @@ pcm_stream_decode(DecoderClient &client, InputStream &is)
try {
CheckChannelCount(value);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
@ -196,8 +196,8 @@ pcm_stream_decode(DecoderClient &client, InputStream &is)
is.LockSeek(offset);
buffer.Clear();
client.CommandFinished();
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
client.SeekError();
}

View File

@ -26,7 +26,7 @@
#include "util/Domain.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <sndfile.h>
@ -93,8 +93,8 @@ sndfile_vio_seek(sf_count_t _offset, int whence, void *user_data)
try {
is.LockSeek(offset);
return is.GetOffset();
} catch (const std::runtime_error &e) {
LogError(e, "Seek failed");
} catch (...) {
LogError(std::current_exception(), "Seek failed");
return -1;
}
}

View File

@ -129,7 +129,7 @@ VorbisDecoder::Seek(uint64_t where_frame)
SeekGranulePos(where_granulepos);
vorbis_synthesis_restart(&dsp);
return true;
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
}
@ -323,7 +323,7 @@ vorbis_stream_decode(DecoderClient &client,
moved it */
try {
input_stream.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
DecoderReader reader(client, input_stream);

View File

@ -295,7 +295,7 @@ struct WavpackInput {
try {
is.LockSeek(pos);
return 0;
} catch (const std::runtime_error &) {
} catch (...) {
return -1;
}
}
@ -520,7 +520,7 @@ wavpack_open_wvc(DecoderClient &client, const char *uri)
try {
return client.OpenUri(uri);
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
}

View File

@ -220,11 +220,11 @@ ServerSocket::Open()
try {
i.Open();
} catch (const std::runtime_error &e) {
} catch (...) {
if (good != nullptr && good->GetSerial() == i.GetSerial()) {
const auto address_string = i.ToString();
const auto good_string = good->ToString();
FormatError(e,
FormatError(std::current_exception(),
"bind to '%s' failed "
"(continuing anyway, because "
"binding to '%s' succeeded)",

View File

@ -29,7 +29,7 @@
#include "util/Domain.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
@ -163,8 +163,9 @@ ReplayGainFilter::Update()
try {
mixer_set_volume(mixer, _volume);
} catch (const std::runtime_error &e) {
LogError(e, "Failed to update hardware mixer");
} catch (...) {
LogError(std::current_exception(),
"Failed to update hardware mixer");
}
} else
pv.SetVolume(volume);

View File

@ -23,7 +23,7 @@
#include "Charset.hxx"
#include "Compiler.h"
#include <stdexcept>
#include <exception>
/* no inlining, please */
AllocatedPath::~AllocatedPath() {}
@ -34,7 +34,7 @@ AllocatedPath::FromUTF8(const char *path_utf8) noexcept
#if defined(HAVE_FS_CHARSET) || defined(_WIN32)
try {
return AllocatedPath(::PathFromUTF8(path_utf8));
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
#else
@ -63,7 +63,7 @@ AllocatedPath::ToUTF8() const noexcept
{
try {
return ::PathToUTF8(c_str());
} catch (const std::runtime_error &) {
} catch (...) {
return std::string();
}
}

View File

@ -62,6 +62,6 @@ try {
"No permission to read directory: %s",
path_fs.ToUTF8().c_str());
}
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
}

View File

@ -21,14 +21,12 @@
#include "Path.hxx"
#include "Charset.hxx"
#include <stdexcept>
std::string
Path::ToUTF8() const noexcept
{
try {
return ::PathToUTF8(c_str());
} catch (const std::runtime_error &) {
} catch (...) {
return std::string();
}
}

View File

@ -62,7 +62,7 @@ input_stream_global_init(EventLoop &event_loop)
"Input plugin '%s' is unavailable",
plugin->name);
continue;
} catch (const std::runtime_error &e) {
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize input plugin '%s'",
plugin->name));
}

View File

@ -63,8 +63,8 @@ TextInputStream::ReadLine()
try {
nbytes = is->LockRead(dest.data, dest.size);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return nullptr;
}

View File

@ -42,7 +42,6 @@
#endif
#include <memory>
#include <stdexcept>
#include <assert.h>
#include <string.h>
@ -95,7 +94,7 @@ try {
#else
#error not implemented
#endif
} catch (const std::runtime_error &) {
} catch (...) {
return AllocatedString<>::Duplicate(src);
}

View File

@ -97,7 +97,7 @@ IcuCollate(const char *a, const char *b) noexcept
return ucol_strcoll(collator, au.begin(), au.size(),
bu.begin(), bu.size());
} catch (const std::runtime_error &) {
} catch (...) {
/* fall back to plain strcasecmp() */
return strcasecmp(a, b);
}
@ -108,18 +108,18 @@ IcuCollate(const char *a, const char *b) noexcept
try {
wa = MultiByteToWideChar(CP_UTF8, a);
} catch (const std::runtime_error &) {
} catch (...) {
try {
wb = MultiByteToWideChar(CP_UTF8, b);
return -1;
} catch (const std::runtime_error &) {
} catch (...) {
return 0;
}
}
try {
wb = MultiByteToWideChar(CP_UTF8, b);
} catch (const std::runtime_error &) {
} catch (...) {
return 1;
}

View File

@ -22,8 +22,6 @@
#include "lib/xiph/OggSyncState.hxx"
#include "input/InputStream.hxx"
#include <stdexcept>
bool
OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet)
{
@ -51,7 +49,7 @@ OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is,
try {
is.LockSeek(offset);
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -43,8 +43,8 @@ output_mixer_get_volume(const AudioOutputControl &ao) noexcept
try {
return mixer_get_volume(mixer);
} catch (const std::runtime_error &e) {
FormatError(e,
} catch (...) {
FormatError(std::current_exception(),
"Failed to read mixer for '%s'",
ao.GetName());
return -1;
@ -86,8 +86,8 @@ output_mixer_set_volume(AudioOutputControl &ao, unsigned volume) noexcept
try {
mixer_set_volume(mixer, volume);
return true;
} catch (const std::runtime_error &e) {
FormatError(e,
} catch (...) {
FormatError(std::current_exception(),
"Failed to set mixer for '%s'",
ao.GetName());
return false;

View File

@ -149,7 +149,7 @@ alsa_mixer_elem_callback(snd_mixer_elem_t *elem, unsigned mask)
try {
int volume = mixer.GetVolume();
mixer.listener.OnMixerVolumeChanged(mixer, volume);
} catch (const std::runtime_error &) {
} catch (...) {
}
}

View File

@ -104,8 +104,8 @@ UpnpNeighborExplorer::GetList() const noexcept
try {
tmp = discovery->GetDirectories();
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
}
List result;

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());
}
}

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;
}

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);
}

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));

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");
}

View File

@ -875,7 +875,7 @@ try {
call */
return;
}
} catch (const std::runtime_error &) {
} catch (...) {
MultiSocketMonitor::Reset();
LockCaughtError();
}

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;
}

View File

@ -856,7 +856,7 @@ try {
PulseOutput po(empty);
po.WaitConnection();
return true;
} catch (const std::runtime_error &e) {
} catch (...) {
return false;
}

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;
}
}

View File

@ -251,7 +251,7 @@ ShoutOutput::Close() noexcept
try {
encoder->End();
WritePage();
} catch (const std::runtime_error &) {
} catch (...) {
/* ignore */
}

View File

@ -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 */
}

View File

@ -37,7 +37,7 @@
#include "thread/Name.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <string.h>
@ -462,8 +462,8 @@ Player::OpenOutput()
try {
const ScopeUnlock unlock(pc.mutex);
pc.outputs.Open(play_audio_format, buffer);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
output_open = false;
@ -564,8 +564,8 @@ Player::SendSilence()
try {
pc.outputs.Play(chunk);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
buffer.Return(chunk);
return false;
}
@ -896,8 +896,8 @@ Player::PlayNextChunk()
try {
play_chunk(pc, *song, chunk, buffer, play_audio_format);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
buffer.Return(chunk);

View File

@ -38,8 +38,6 @@
#include "config/ConfigGlobal.hxx"
#include "config/Block.hxx"
#include <stdexcept>
#include <assert.h>
#include <string.h>
@ -196,7 +194,7 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, const char *mime)
fresh start */
try {
is->LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
auto playlist = playlist_plugin_open_stream(plugin,
@ -240,7 +238,7 @@ playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
fresh start */
try {
is->LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
}
auto playlist = playlist_plugin_open_stream(plugin,

View File

@ -26,8 +26,6 @@
#include "util/UriUtil.hxx"
#include "DetachedSong.hxx"
#include <stdexcept>
#include <string.h>
static void
@ -53,7 +51,7 @@ try {
merge_song_metadata(song, tmp);
return true;
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}

View File

@ -26,7 +26,7 @@
#include "fs/Path.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#include <assert.h>
@ -46,8 +46,8 @@ try {
auto is = OpenLocalInputStream(path, mutex, cond);
return playlist_list_open_stream_suffix(std::move(is),
suffix_utf8.c_str());
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return nullptr;
}
@ -64,8 +64,8 @@ try {
playlist = playlist_open_path_suffix(path, mutex, cond);
return playlist;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return nullptr;
}
@ -80,7 +80,7 @@ try {
auto is = InputStream::OpenReady(uri, mutex, cond);
return playlist_list_open_stream(std::move(is), uri);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return nullptr;
}

View File

@ -23,8 +23,6 @@
#include "db/LightSong.hxx"
#include "DetachedSong.hxx"
#include <stdexcept>
static bool
UpdatePlaylistSong(const Database &db, DetachedSong &song)
{
@ -36,7 +34,7 @@ UpdatePlaylistSong(const Database &db, DetachedSong &song)
const LightSong *original;
try {
original = db.GetSong(song.GetURI());
} catch (const std::runtime_error &e) {
} catch (...) {
/* not found - shouldn't happen, because the update
thread should ensure that all stale Song instances
have been purged */

View File

@ -29,6 +29,8 @@
#include "util/StringCompare.hxx"
#include "Log.hxx"
#include <exception>
#include <stdlib.h>
#define PRIO_LABEL "Prio: "
@ -96,8 +98,8 @@ queue_load_song(TextFile &file, const SongLoader &loader,
try {
song = song_load(file, uri);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return;
}
} else {

View File

@ -25,8 +25,6 @@
#include "util/Alloc.hxx"
#include "util/ScopeExit.hxx"
#include <stdexcept>
#include <string.h>
#include <stdlib.h>
@ -96,7 +94,7 @@ sticker_song_find_cb(const char *uri, const char *value, void *user_data)
const LightSong *song = db->GetSong(uri);
data->func(*song, value, data->user_data);
db->ReturnSong(song);
} catch (const std::runtime_error &e) {
} catch (...) {
}
}

View File

@ -299,7 +299,7 @@ CompositeStorage::OpenDirectory(const char *uri)
try {
other = f.directory->storage->OpenDirectory(f.uri);
} catch (const std::runtime_error &) {
} catch (...) {
}
return new CompositeDirectoryReader(other, directory->children);

View File

@ -194,7 +194,7 @@ ParseTimeStamp(const char *s)
try {
// TODO: make this more robust
return ParseTimePoint(s, "%a, %d %b %Y %T %Z");
} catch (const std::runtime_error &) {
} catch (...) {
return std::chrono::system_clock::time_point::min();
}
}

View File

@ -123,7 +123,7 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept
{
try {
return MapFSOrThrow(uri_utf8);
} catch (const std::runtime_error &) {
} catch (...) {
return AllocatedPath::Null();
}
}

View File

@ -24,7 +24,6 @@
#include "util/StringView.hxx"
#include <memory>
#include <stdexcept>
#include <stdint.h>
#include <assert.h>
@ -104,6 +103,6 @@ try {
}
return true;
} catch (const std::runtime_error &) {
return false;
} catch (...) {
return false;
}

View File

@ -28,7 +28,7 @@
#include "input/LocalOpen.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
bool
ScanGenericTags(InputStream &is, const TagHandler &handler, void *ctx)
@ -39,7 +39,7 @@ ScanGenericTags(InputStream &is, const TagHandler &handler, void *ctx)
#ifdef ENABLE_ID3TAG
try {
is.LockRewind();
} catch (const std::runtime_error &) {
} catch (...) {
return false;
}
@ -57,7 +57,7 @@ try {
auto is = OpenLocalInputStream(path, mutex, cond);
return ScanGenericTags(*is, handler, ctx);
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}

View File

@ -27,7 +27,6 @@
#include <id3tag.h>
#include <algorithm>
#include <stdexcept>
static constexpr size_t ID3V1_SIZE = 128;
@ -46,7 +45,7 @@ try {
is.ReadFull(buf, sizeof(buf));
return id3_tag_query(buf, sizeof(buf));
} catch (const std::runtime_error &) {
} catch (...) {
return 0;
}
@ -77,7 +76,7 @@ try {
is.ReadFull(end, remaining);
return UniqueId3Tag(id3_tag_parse(tag_buffer.get(), tag_size));
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -87,7 +86,7 @@ try {
is.Seek(offset);
return ReadId3Tag(is);
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -98,7 +97,7 @@ try {
is.ReadFull(buffer, ID3V1_SIZE);
return UniqueId3Tag(id3_tag_parse(buffer, ID3V1_SIZE));
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -107,7 +106,7 @@ ReadId3v1Tag(InputStream &is, offset_type offset)
try {
is.Seek(offset);
return ReadId3v1Tag(is);
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -140,7 +139,7 @@ try {
}
return tag;
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -181,7 +180,7 @@ try {
/* We have an id3v2 tag, so ditch v1tag */
return tag;
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -191,7 +190,7 @@ try {
size_t size;
try {
size = riff_seek_id3(is);
} catch (const std::runtime_error &) {
} catch (...) {
size = aiff_seek_id3(is);
}
@ -203,7 +202,7 @@ try {
is.ReadFull(buffer.get(), size);
return UniqueId3Tag(id3_tag_parse(buffer.get(), size));
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}
@ -220,6 +219,6 @@ try {
}
return tag;
} catch (const std::runtime_error &) {
} catch (...) {
return nullptr;
}

View File

@ -32,7 +32,7 @@
#include <id3tag.h>
#include <string>
#include <stdexcept>
#include <exception>
#include <string.h>
#include <stdlib.h>
@ -349,8 +349,8 @@ tag_id3_scan(InputStream &is,
tag = tag_id3_load(is);
if (!tag)
return false;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return false;
}

View File

@ -24,8 +24,6 @@
#include "util/StringBuffer.hxx"
#include "Compiler.h"
#include <stdexcept>
#include <unistd.h>
#include <stdio.h>
@ -83,7 +81,7 @@ FakeDecoder::Read(InputStream &is, void *buffer, size_t length)
{
try {
return is.LockRead(buffer, length);
} catch (const std::runtime_error &e) {
} catch (...) {
return 0;
}
}

View File

@ -43,7 +43,7 @@ public:
try {
IcuConverter::Create("doesntexist");
CPPUNIT_FAIL("Exception expected");
} catch (const std::runtime_error &) {
} catch (...) {
}
}
@ -56,7 +56,7 @@ public:
try {
auto f = converter->FromUTF8(i);
CPPUNIT_FAIL("Exception expected");
} catch (const std::runtime_error &) {
} catch (...) {
}
}

View File

@ -23,6 +23,8 @@
#include "event/Loop.hxx"
#include "Log.hxx"
#include <exception>
#include <sys/inotify.h>
static constexpr unsigned IN_MASK =
@ -59,7 +61,7 @@ try {
event_loop.Run();
return EXIT_SUCCESS;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return EXIT_FAILURE;
}

View File

@ -23,7 +23,7 @@
#include "net/SocketAddress.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <exception>
#ifdef _WIN32
#include <ws2tcpip.h>
@ -53,7 +53,7 @@ try {
freeaddrinfo(ai);
return EXIT_SUCCESS;
} catch (const std::runtime_error &e) {
LogError(e);
} catch (...) {
LogError(std::current_exception());
return EXIT_FAILURE;
}