异常后返回的对象?

yes*_*aaj 1 c++ exception return-value

   int somefunction(bool a)
    {
      try
      {
        if(a)
        throw Error("msg");
        return 2;
      }
     catch (Error const & error)
     {
       //do i need to return anything here??
       //return -1;
     }
    }
Run Code Online (Sandbox Code Playgroud)

wor*_*ad3 6

您需要返回一些内容或重新抛出异常(或抛出一个新异常).您只需使用关键字即可重新抛出相同的异常

throw
Run Code Online (Sandbox Code Playgroud)

在catch块中,之后没有异常或参数.