There is no call to exit() in the code you presented.
In the code you presented, you have 2 separate object instances of the A class:
A a; // <-- here
A & AccessA() {
static A obj; // <-- here
return obj;
}
The 1st object is being created in global scope during program startup, and the 2nd object is being created in static memory the first time AccessA() is called at runtime. The global object is created before your project's WinMain() function is executed The code presented is not calling AccessA() at all, so the compiler/linker is free to optimize it away, if it wants to.
I already explained that in detail in my previous reply. Go re-read it again more carefully. Do you understand the difference between a function-try block and a normal non-function-level try block?
No, there is no explicit re-throw statement in the catch block. But the catch block is performing an implicit re-throw, because you are using a function-try block instead of a normal try block:
If you really want to swallow the exception, use a normal try block instead of a function-try block, eg:
class A {
A() noexcept {
try {
throw std::logic_error("test");
}
catch (std::exception const &ex) {
std::cout << "Caught an STL exception" << std::endl;
}
}
};
Notice the try-catch is now inside the constructor's body, rather than around the body as in your original example.