changeset 121:56e537a7bb99

Error handling
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 27 Oct 2016 14:01:35 +0100
parents 88ecaf8b163a
children 2380d5865355
files vamp-client/AutoPlugin.h vamp-client/ProcessQtTransport.h vamp-client/SynchronousTransport.h
diffstat 3 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/vamp-client/AutoPlugin.h	Thu Oct 27 13:42:07 2016 +0100
+++ b/vamp-client/AutoPlugin.h	Thu Oct 27 14:01:35 2016 +0100
@@ -59,8 +59,13 @@
         req.pluginKey = pluginKey;
         req.inputSampleRate = inputSampleRate;
         req.adapterFlags = adapterFlags;
-        LoadResponse resp = m_client.loadPlugin(req);
-        m_plugin = resp.plugin;
+        try {
+            LoadResponse resp = m_client.loadPlugin(req);
+            m_plugin = resp.plugin;
+        } catch (ServerCrashed c) {
+            std::cerr << c.what() << std::endl;
+            m_plugin = 0;
+        }
     }
 
     virtual ~AutoPlugin() {
--- a/vamp-client/ProcessQtTransport.h	Thu Oct 27 13:42:07 2016 +0100
+++ b/vamp-client/ProcessQtTransport.h	Thu Oct 27 14:01:35 2016 +0100
@@ -142,8 +142,7 @@
                         std::cerr << "Server failed during request with error code "
                                   << err << std::endl;
                     }
-                    //!!! + catch
-                    throw std::runtime_error("Piper server exited unexpectedly");
+                    throw ServerCrashed();
                 }
             } else {
                 size_t formerSize = buffer.size();
--- a/vamp-client/SynchronousTransport.h	Thu Oct 27 13:42:07 2016 +0100
+++ b/vamp-client/SynchronousTransport.h	Thu Oct 27 14:01:35 2016 +0100
@@ -38,6 +38,7 @@
 
 #include <vector>
 #include <cstdlib>
+#include <stdexcept>
 
 namespace piper_vamp {
 namespace client {
@@ -50,6 +51,12 @@
     virtual bool isComplete(const std::vector<char> &message) const = 0;
 };
 
+class ServerCrashed : public std::runtime_error
+{
+public:
+    ServerCrashed() : std::runtime_error("Piper server exited unexpectedly") {}
+};
+
 class SynchronousTransport // interface
 {
 public: