MISRA-C++:2008[8-4-3] : return in all exit path in function

Viewed 487

When testing my code (static analysis) to see if i respect misra c++ 2008, i get the following error

Function does not return a value on all paths.

The function looks like

int* Dosomething(string v)
{
   int* retvalue = NULL;

   if( 0 == exists(v) )
   {
      throw("error: value doesn't exist");
   }
   else
   {
     retvalue = dosomecomputations(v);
   }

   return retvalue;
}

I really need to throw an exception, because depending of the error the caller shall do something. The possible list of errors can be big and it is not just that the value doesn't exist as in this sample of code.

How can i manage it? I think that in this case the tool i'm using should not see it as a non-compliance to misra.

Thanks for your advise.

rony.

1 Answers
Related