diff runner/FeatureExtractionManager.cpp @ 21:9a4e410bda7a

* Add --force option, and throw/catch exceptions for failure cases rather than exiting directly
author Chris Cannam
date Tue, 07 Jul 2009 10:34:27 +0000
parents bd1deebe1129
children 4ab7c925f7ac
line wrap: on
line diff
--- a/runner/FeatureExtractionManager.cpp	Mon Jun 29 13:47:12 2009 +0000
+++ b/runner/FeatureExtractionManager.cpp	Tue Jul 07 10:34:27 2009 +0000
@@ -22,6 +22,8 @@
 #include <vamp-hostsdk/PluginWrapper.h>
 #include <vamp-hostsdk/PluginLoader.h>
 
+#include "base/Exceptions.h"
+
 #include <iostream>
 
 using namespace std;
@@ -373,7 +375,7 @@
     if (!source.isAvailable()) {
         cerr << "ERROR: File or URL \"" << audioSource.toStdString()
              << "\" could not be located" << endl;
-        exit(1);
+        throw FileNotFound(audioSource);
     }
     
     source.waitForData();
@@ -389,7 +391,7 @@
         } else {
             cerr << "ERROR: Playlist \"" << audioSource.toStdString()
                  << "\" could not be opened" << endl;
-            exit(1);
+            throw FileNotFound(audioSource);
         }
     }
 
@@ -402,9 +404,7 @@
         AudioFileReaderFactory::createReader(source, m_sampleRate, &retrievalProgress);
     
     if (!reader) {
-        cerr << "ERROR: File or URL \"" << audioSource.toStdString()
-             << "\" could not be opened" << endl;
-        exit(1);
+        throw FailedToOpenFile(audioSource);
     }
 
     size_t channels = reader->getChannelCount();
@@ -415,9 +415,10 @@
 
     // reject file if it has too few channels, plugin will handle if it has too many
     if ((int)channels < m_channels) {
-        //!!! should not be terminating here!
-        cerr << "ERROR: File or URL \"" << audioSource.toStdString() << "\" has less than " << m_channels << " channels" << endl;
-        exit(1);
+        throw FileOperationFailed
+            (audioSource,
+             QString("read sufficient channels (found %1, require %2)")
+             .arg(channels).arg(m_channels));
     }
     
     // allocate audio buffers