C++ catch构造函数异常

Any*_*orn 2 c++ constructor exception

我似乎不明白如何捕获构造函数异常.这是相关代码:

     struct Thread {
            rysq::cuda::Fock fock_;
            template<class iterator>
            Thread(const rysq::cuda::Centers &centers,
                   const iterator (&blocks)[4])
                : fock_()
            {
                if (!fock_) throw;
           }
      };

      Thread *ct;
      try { ct = new Thread(centers_, blocks); }
      catch(...) { return false; } // catch never happens,
Run Code Online (Sandbox Code Playgroud)

所以catch语句不执行,我得到未处理的异常.我做错了什么?这是使用g ++的直接C++.

Jam*_*lis 8

你必须扔一个物体,例如,

throw std::exception();
Run Code Online (Sandbox Code Playgroud)

throw没有操作数只在catch块内部使用,以重新抛出块处理的异常catch.

  • @Billy:在C++中,原语也是对象.对象只是"存储区域"(在语言标准的最开始的某个地方). (3认同)