-
Compiling error
Code:
#include <iostream>
int main() {
try {
throw std::exception("test");
} catch(std::exception& e) {
std::cerr << e.what() << '\n';
} catch(...) {
std::cerr << "...\n";
}
}
This compiles under Visual Studio but in g++ it causes an error "error: no matching function for call to `std::exception::exception(const char[5])"
So why does it work under one compiler but not the other?
-
You are probably using a MSVC compiler extension. std::exception does not have a constructor that takes a string of any sort, though std::logic_error and std::runtime_error have constructors that take a std::string by const reference.
Oh, and you should #include <exception> for std::exception.