2011-02-01 145 views
17

我试图使用Qt(4.6.3)+ MinGW的编译如下代码:缺少的std :: runtime_error在QT + MinGW的

#include <QtCore/QCoreApplication> 
#include <exception> 

int main(int argc, char *argv[]) 
{ 
    throw std::runtime_error(""); 

    QCoreApplication a(argc, argv); 

    return a.exec(); 
} 

...并得到这个错误:

..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std' 
从头开始(控制台应用程序)创建

项目,亲文件:

QT  += core 

QT  -= gui 

TARGET = untitled11 
CONFIG += console 
CONFIG -= app_bundle 

TEMPLATE = app 

SOURCES += main.cpp 

试图编译这个使用Qt + MSVC2008编译器 - 工作正常。

这是一个标准例外,不知道为什么会丢失。

回答

44

<exception>只定义了基类std::exception类;如果您想要子类,例如std::runtime_error,则必须包含<stdexcept>标题。

+0

+1 AFAIK,不存在。 – Simone 2011-02-01 11:15:40