changeset 48:42ddc9bbc168

rely on OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 02 Aug 2015 09:34:56 +0200
parents 3c6edd600dcc
children b8b1ea028da9
files Plugin/Dicom.cpp Plugin/DicomResults.cpp Plugin/QidoRs.cpp Plugin/StowRs.cpp Plugin/WadoRs.cpp
diffstat 5 files changed, 81 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Plugin/Dicom.cpp	Sun Aug 02 09:28:32 2015 +0200
+++ b/Plugin/Dicom.cpp	Sun Aug 02 09:34:56 2015 +0200
@@ -27,6 +27,7 @@
 #include <boost/lexical_cast.hpp>
 #include <json/writer.h>
 
+#include "../Orthanc/Core/OrthancException.h"
 #include "../Orthanc/Core/Toolbox.h"
 
 namespace OrthancPlugins
@@ -65,8 +66,8 @@
     reader_.SetStream(stream);
     if (!reader_.Read())
     {
-      throw std::runtime_error("GDCM cannot read this DICOM instance of length " + 
-                               boost::lexical_cast<std::string>(dicom.size()));
+      throw Orthanc::OrthancException("GDCM cannot read this DICOM instance of length " + 
+                                      boost::lexical_cast<std::string>(dicom.size()));
     }
   }
 
@@ -163,7 +164,7 @@
       return "RetrieveURL";
     }
 
-    //throw std::runtime_error("Unknown keyword for tag: " + FormatTag(tag));
+    //throw Orthanc::OrthancException("Unknown keyword for tag: " + FormatTag(tag));
     return NULL;
   }
 
--- a/Plugin/DicomResults.cpp	Sun Aug 02 09:28:32 2015 +0200
+++ b/Plugin/DicomResults.cpp	Sun Aug 02 09:34:56 2015 +0200
@@ -21,6 +21,7 @@
 #include "DicomResults.h"
 
 #include "Dicom.h"
+#include "../Orthanc/Core/OrthancException.h"
 
 namespace OrthancPlugins
 {
@@ -41,7 +42,7 @@
     if (isXml_ &&
         OrthancPluginStartMultipartAnswer(context_, output_, "related", "application/dicom+xml") != 0)
     {
-      throw std::runtime_error("Unable to create a multipart stream of DICOM+XML answers");
+      throw Orthanc::OrthancException("Unable to create a multipart stream of DICOM+XML answers");
     }
 
     jsonWriter_.AddChunk("[\n");
@@ -58,7 +59,7 @@
 
       if (OrthancPluginSendMultipartItem(context_, output_, answer.c_str(), answer.size()) != 0)
       {
-        throw std::runtime_error("Unable to write an item to a multipart stream of DICOM+XML answers");
+        throw Orthanc::OrthancException("Unable to write an item to a multipart stream of DICOM+XML answers");
       }
     }
     else
--- a/Plugin/QidoRs.cpp	Sun Aug 02 09:28:32 2015 +0200
+++ b/Plugin/QidoRs.cpp	Sun Aug 02 09:34:56 2015 +0200
@@ -26,6 +26,7 @@
 #include "DicomResults.h"
 #include "Configuration.h"
 #include "../Orthanc/Core/Toolbox.h"
+#include "../Orthanc/Core/OrthancException.h"
 
 #include <gdcmTag.h>
 #include <list>
@@ -110,11 +111,11 @@
         {
           if (key.find('.') != std::string::npos)
           {
-            throw std::runtime_error("This QIDO-RS implementation does not support search over sequences: " + key);
+            throw Orthanc::OrthancException("This QIDO-RS implementation does not support search over sequences: " + key);
           }
           else
           {
-            throw std::runtime_error("Illegal tag name in QIDO-RS: " + key);
+            throw Orthanc::OrthancException("Illegal tag name in QIDO-RS: " + key);
           }
         }
 
@@ -303,7 +304,7 @@
           break;
 
         default:
-          throw std::runtime_error("Internal error");
+          throw Orthanc::OrthancException("Internal error");
       }
     }
 
@@ -342,7 +343,7 @@
           }
           else
           {
-            throw std::runtime_error("Not a proper value for fuzzy matching (true or false): " + value);
+            throw Orthanc::OrthancException("Not a proper value for fuzzy matching (true or false): " + value);
           }
         }
         else if (key == "includefield")
@@ -605,7 +606,7 @@
           break;
 
         default:
-          throw std::runtime_error("Internal error");
+          throw Orthanc::OrthancException("Internal error");
       }
 
 
@@ -644,7 +645,7 @@
           break;
 
         default:
-          throw std::runtime_error("Internal error");
+          throw Orthanc::OrthancException("Internal error");
       }
     }
 
@@ -671,7 +672,7 @@
           break;
 
         default:
-          throw std::runtime_error("Internal error");
+          throw Orthanc::OrthancException("Internal error");
       }
     }
 
@@ -700,7 +701,7 @@
             break;
 
           default:
-            throw std::runtime_error("Internal error");
+            throw Orthanc::OrthancException("Internal error");
         }
 
         Json::Value tmp;
@@ -789,12 +790,17 @@
 
     return 0;
   }
-  catch (std::runtime_error& e)
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
+  catch (boost::bad_lexical_cast& e)
   {
     OrthancPluginLogError(context_, e.what());
     return -1;
   }
-  catch (boost::bad_lexical_cast& e)
+  catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
     return -1;
@@ -831,12 +837,17 @@
 
     return 0;
   }
-  catch (std::runtime_error& e)
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
+  catch (boost::bad_lexical_cast& e)
   {
     OrthancPluginLogError(context_, e.what());
     return -1;
   }
-  catch (boost::bad_lexical_cast& e)
+  catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
     return -1;
@@ -881,9 +892,9 @@
 
     return 0;
   }
-  catch (std::runtime_error& e)
+  catch (Orthanc::OrthancException& e)
   {
-    OrthancPluginLogError(context_, e.what());
+    OrthancPluginLogError(context_, e.What());
     return -1;
   }
   catch (boost::bad_lexical_cast& e)
@@ -891,4 +902,9 @@
     OrthancPluginLogError(context_, e.what());
     return -1;
   }
+  catch (std::runtime_error& e)
+  {
+    OrthancPluginLogError(context_, e.what());
+    return -1;
+  }
 }
--- a/Plugin/StowRs.cpp	Sun Aug 02 09:28:32 2015 +0200
+++ b/Plugin/StowRs.cpp	Sun Aug 02 09:34:56 2015 +0200
@@ -24,6 +24,9 @@
 #include "Configuration.h"
 #include "Dicom.h"
 #include "../Orthanc/Core/Toolbox.h"
+#include "../Orthanc/Core/OrthancException.h"
+
+#include <stdexcept>
 
 
 static void SetTag(gdcm::DataSet& dataset,
@@ -228,6 +231,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
--- a/Plugin/WadoRs.cpp	Sun Aug 02 09:28:32 2015 +0200
+++ b/Plugin/WadoRs.cpp	Sun Aug 02 09:34:56 2015 +0200
@@ -26,6 +26,7 @@
 #include "Dicom.h"
 #include "DicomResults.h"
 #include "../Orthanc/Core/Toolbox.h"
+#include "../Orthanc/Core/OrthancException.h"
 
 static bool AcceptMultipartDicom(const OrthancPluginHttpRequest* request)
 {
@@ -397,6 +398,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -425,6 +431,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -464,6 +475,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -494,6 +510,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -523,6 +544,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -552,6 +578,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
@@ -670,6 +701,11 @@
 
     return 0;
   }
+  catch (Orthanc::OrthancException& e)
+  {
+    OrthancPluginLogError(context_, e.What());
+    return -1;
+  }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());