27

I've tried to compile the following code using Qt(4.6.3) + MinGW:

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

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

    QCoreApplication a(argc, argv);

    return a.exec();
}

... and got this error:

..\untitled11\main.cpp:6: error: 'runtime_error' is not a member of 'std'

Project created from scratch(console application), the pro file:

QT       += core

QT       -= gui

TARGET = untitled11
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

Tried to compile this using Qt+MSVC2008 compiler - works fine.

This is a standard exception, have no idea why is missing.

1 Answer 1

75

<exception> defines only the base std::exceptionclass; if you want child classes like std::runtime_error, you must include the <stdexcept> header.

2
  • 4
    It exists, and contains base std::exception class, while <stdexcept> contains standard child exception classes. cplusplus.com/reference/std/exception
    – CharlesB
    Commented Feb 1, 2011 at 11:17
  • +1000 it was driving me crazy when using std::invalid_argument (on Ubuntu, gcc 4.7). Thank you! Commented Mar 22, 2015 at 20:45

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.