Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法捕获'catch(const std::exception&;ex)中的std::invalid_参数`_C++_Exception_Try Catch - Fatal编程技术网

C++ 无法捕获'catch(const std::exception&;ex)中的std::invalid_参数`

C++ 无法捕获'catch(const std::exception&;ex)中的std::invalid_参数`,c++,exception,try-catch,C++,Exception,Try Catch,我有以下代码: void App::start() try { initialize(); //... m_errorCode = 0; } catch (const std::exception &ex) { std::cerr << ex.what() << '\n'; m_errorCode = -1; } catch (...) { std::cerr << "Unknown exception

我有以下代码:

void App::start()
try
{
    initialize();
    //...

    m_errorCode = 0;
}
catch (const std::exception &ex)
{
    std::cerr << ex.what() << '\n';
    m_errorCode = -1;
}
catch (...)
{
    std::cerr << "Unknown exception\n";
    m_errorCode = -2;
}

void App::initialize()
{
    m_controller = createController();
    //...
}

std::unique_ptr<IController> App::createController() const
{
    if (m_config.m_controllerType == "iot_v1")
    {
        return std::make_unique<ControllerIotV1>();
    }

    if (m_config.m_controllerType == "iot_v2")
    {
        return std::make_unique<ControllerIotV2>();
    }

    throw new std::invalid_argument("Unsupported controller type.");
}
void应用程序::start()
尝试
{
初始化();
//...
m_errorCode=0;
}
捕获(const std::exception&ex)
{

std::cerr您应该按值抛出(无新的
new
):


您缺少的主要内容是编译、运行和演示问题的最小完整示例。请阅读
new
的功能。
const std::exception&ex
≠ <代码>标准::异常常量*ex
throw std::invalid_argument("Unsupported controller type.");