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