Catch all exceptions not caught in exiv2 cli-tool

It effectively looks the same as before, only now we don't call abort() but
instead clean up everything gracefully.
v0.27.3
Dan Čermák 7 years ago
parent 937a1a2bd0
commit f4e8ed2fd4

@ -146,30 +146,36 @@ int main(int argc, char* const argv[])
return 0; return 0;
} }
// Create the required action class
Action::TaskFactory& taskFactory = Action::TaskFactory::instance();
Action::Task::AutoPtr task
= taskFactory.create(Action::TaskType(params.action_));
assert(task.get());
// Process all files
int rc = 0; int rc = 0;
int n = 1;
int s = static_cast<int>(params.files_.size()); try {
int w = s > 9 ? s > 99 ? 3 : 2 : 1; // Create the required action class
for (Params::Files::const_iterator i = params.files_.begin(); Action::TaskFactory& taskFactory = Action::TaskFactory::instance();
i != params.files_.end(); ++i) { Action::Task::AutoPtr task = taskFactory.create(Action::TaskType(params.action_));
if (params.verbose_) { assert(task.get());
std::cout << _("File") << " " << std::setw(w) << std::right << n++ << "/" << s << ": "
<< *i << std::endl; // Process all files
int n = 1;
int s = static_cast<int>(params.files_.size());
int w = s > 9 ? s > 99 ? 3 : 2 : 1;
for (Params::Files::const_iterator i = params.files_.begin(); i != params.files_.end(); ++i) {
if (params.verbose_) {
std::cout << _("File") << " " << std::setw(w) << std::right << n++ << "/" << s << ": " << *i
<< std::endl;
}
int ret = task->run(*i);
if (rc == 0)
rc = ret;
} }
int ret = task->run(*i);
if (rc == 0) rc = ret;
}
taskFactory.cleanup(); taskFactory.cleanup();
params.cleanup(); params.cleanup();
Exiv2::XmpParser::terminate(); Exiv2::XmpParser::terminate();
} catch (const std::exception& exc) {
std::cerr << "Uncaught exception: " << exc.what() << std::endl;
rc = 1;
}
// Return a positive one byte code for better consistency across platforms // Return a positive one byte code for better consistency across platforms
return static_cast<unsigned int>(rc) % 256; return static_cast<unsigned int>(rc) % 256;

Loading…
Cancel
Save