Refactored Optimize(...) function to throw exceptions instead of returning null

 * INetwork::Optimize(...) states that the function should throw an exception
   if it fails but the implementation in Network.cpp returned null in some
   scenarios instead. This has led to some confusion amongst users.

Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I358d1293232c9464772aa0e39ab3355e3570c823
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp
index 1f59ed5..668b634 100644
--- a/src/armnn/Network.cpp
+++ b/src/armnn/Network.cpp
@@ -1018,7 +1018,7 @@
 {
     if (backendPreferences.empty())
     {
-        throw armnn::InvalidArgumentException("Invoked Optimize with no backends specified");
+        throw InvalidArgumentException("Invoked Optimize with no backends specified");
     }
 
     if (options.m_ReduceFp32ToFp16 && options.m_ReduceFp32ToBf16)
@@ -1082,7 +1082,7 @@
         failureMsg << "None of the preferred backends " << backendPreferences
                    << " are supported. Current platform provides " << backendSettings.m_SupportedBackends;
         ReportError(failureMsg.str(), messages);
-        return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
+        throw InvalidArgumentException(failureMsg.str());
     }
 
     // Create a map to temporarily hold initialized backend objects
@@ -1100,7 +1100,7 @@
     if (assignBackendsResult.m_Error)
     {
         // Failed to assign a backend to each layer
-        return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
+        throw InvalidArgumentException("Failed to assign a backend to each layer");
     }
 
     Optimizer::Pass(optGraph, MakeOptimizations(OptimizeInverseConversionsFp16(),
@@ -1114,7 +1114,7 @@
     if (backendOptimizationResult.m_Error)
     {
         // Failed to apply the backend-specific optimizations
-        return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
+        throw InvalidArgumentException("Failed to apply the backend-specific optimizations");
     }
 
     // If the debug flag is set, then insert a DebugLayer after each layer