From 01d4ed3025007fd4115120e59c583c7fba02a13d Mon Sep 17 00:00:00 2001 From: heckflosse Date: Thu, 21 Jun 2018 19:19:25 +0200 Subject: [PATCH] Catch exceptions inside loop to continue listing files if there is an exception thrown for one or more files --- rtgui/filecatalog.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 86c530661..19830951b 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -564,21 +564,31 @@ std::vector FileCatalog::getFileList () auto enumerator = dir->enumerate_children ("standard::name"); - while (auto file = enumerator->next_file ()) { + while (true) { + try { + auto file = enumerator->next_file (); + if (!file) { + break; + } - const Glib::ustring fname = file->get_name (); + const Glib::ustring fname = file->get_name (); - auto lastdot = fname.find_last_of ('.'); - if (lastdot >= fname.length () - 1) { - continue; + auto lastdot = fname.find_last_of ('.'); + if (lastdot >= fname.length () - 1) { + continue; + } + + const auto fext = fname.substr (lastdot + 1).lowercase (); + if (extensions.count (fext) == 0) { + continue; + } + + names.emplace_back (Glib::build_filename (selectedDirectory, fname)); + } catch (Glib::Exception& exception) { + if (options.rtSettings.verbose) { + std::cerr << exception.what () << std::endl; + } } - - const auto fext = fname.substr (lastdot + 1).lowercase (); - if (extensions.count (fext) == 0) { - continue; - } - - names.emplace_back (Glib::build_filename (selectedDirectory, fname)); } } catch (Glib::Exception& exception) {