Fix uncatched exception (#7058)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 30 Aug 2019 05:49:30 +0000 (14:49 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 30 Aug 2019 05:49:30 +0000 (14:49 +0900)
Operand::operandSize() can throw exeception because sizeOfDataType() in DataType.h can throw runtime exception

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksExecution.cc
runtimes/neurun/frontend/nnapi/wrapper/ANeuralNetworksModel.cc

index 6598c61..3ac73a4 100644 (file)
@@ -63,12 +63,21 @@ ANeuralNetworksExecution::getOutputOperandIndex(int32_t index) noexcept
 bool ANeuralNetworksExecution::compareDataType(const ANeuralNetworksOperandType *type,
                                                const neurun::model::OperandIndex index) noexcept
 {
-  const auto operand_type = _execution->model().operands.at(index).typeInfo();
-  const auto typeInfo = NNAPIConvert::getTypeInfo(type);
-
-  if (operand_type != typeInfo)
+  try
+  {
+    const auto operand_type = _execution->model().operands.at(index).typeInfo();
+    const auto typeInfo = NNAPIConvert::getTypeInfo(type);
+
+    if (operand_type != typeInfo)
+    {
+      // Data type mismatch
+      return false;
+    }
+  }
+  catch (const std::exception &e)
   {
-    // Data type mismatch
+    VERBOSE(EXCEPTION) << e.what() << std::endl;
+
     return false;
   }
 
@@ -99,7 +108,16 @@ bool ANeuralNetworksExecution::haveUnspecifiedDims(const neurun::model::OperandI
 
 size_t ANeuralNetworksExecution::getOperandSize(const neurun::model::OperandIndex index) noexcept
 {
-  return _execution->model().operands.at(index).operandSize();
+  try
+  {
+    return _execution->model().operands.at(index).operandSize();
+  }
+  catch (const std::exception &e)
+  {
+    VERBOSE(EXCEPTION) << e.what() << std::endl;
+
+    return 0;
+  }
 }
 
 bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOperandType *type,
index 268eb0c..e3bb291 100644 (file)
@@ -214,7 +214,16 @@ bool ANeuralNetworksModel::isExistOperand(uint32_t index) noexcept
 
 size_t ANeuralNetworksModel::operandSize(uint32_t index) noexcept
 {
-  return _model->operands.at(neurun::model::OperandIndex{index}).operandSize();
+  try
+  {
+    return _model->operands.at(neurun::model::OperandIndex{index}).operandSize();
+  }
+  catch (const std::exception &e)
+  {
+    VERBOSE(EXCEPTION) << e.what() << '\n';
+
+    return 0;
+  }
 }
 
 bool ANeuralNetworksModel::isUsageSet(uint32_t index) noexcept