Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

runtime_error was not declared in this scope for g++ 4.1.2

Tags:

c++

linux

gcc

The same code is working fine on gcc 4.5.2 but when trying to compile it on gcc 4.1.2, I get the error ‘runtime_error’ was not declared in this scope.

I do have

#include <stdexcept>

Is this a problem with gcc 4.1.2?

Code excerpt

// Constructor
if (resource cannot be acquired)
  throw std::runtime_error("Blah Blah");
like image 969
Dat Chu Avatar asked Apr 03 '11 01:04

Dat Chu


People also ask

How do I fix error malloc is not declared in this scope?

You should use new in C++ code rather than malloc so it becomes new GLubyte*[RESOURCE_LENGTH] instead. When you #include <cstdlib> it will load malloc into namespace std , so refer to std::malloc (or #include <stdlib. h> instead).

What is Runtime_error in exception handling?

class runtime_error; Defines a type of object to be thrown as exception. It reports errors that are due to events beyond the scope of the program and can not be easily predicted.


3 Answers

Visual Studio says that runtime_error should be defined in <stdexcept>, so I'm guessing that GCC 4.1.2 is just out of date here.

like image 53
Puppy Avatar answered Oct 13 '22 18:10

Puppy


Do you have using namespace std; or using std::runtime_error;? If not, then you need to fully qualify the name and use std::runtime_error rather than just runtime_error.

like image 31
ildjarn Avatar answered Oct 13 '22 18:10

ildjarn


gcc 4.1 is relatively old. 4.5 is more standard compliant. Maybe you triggered a compiler's bug

like image 2
BЈовић Avatar answered Oct 13 '22 17:10

BЈовић