I wrote the following program:
// Example program
#include <iostream>
#include <string>
#include <exception>
struct A {
A() {
std::cout << "A ctor" << std::endl;
}
~A() {
std::cout << "A dtor" << std::endl;
try {
throw std::exception();
} catch (std::exception &e) {
std::cout << "Internal exception caught" << std::endl;
}
}
};
int main()
{
try {
A a;
throw std::exception();
} catch (std::exception &e) {
std::cout << "External exception caught" << std::endl;
}
}
The output I expected was:
A ctor
A dtor
Internal exception caught
External exception caught
And this is what I'm getting in GCC. But when I'm using Visual Studio (version 2013) the output I'm getting is:
A ctor
External exception caught
What's going on here?