When it takes a program too long to load, it is because the program is doing too much non-exception work. The exception-handling code is not even being loaded unless it's throwing while it loads, which would just be bad design.
I just built the following code with g++ v7.4 (from MSYS64 on Windows):
#include <math.h>
#include <stdexcept>
void exitWithMessageException() {
if (random() == 4321)
throw std::runtime_error("Halt! Who goes there?");
}
int main() {
exitWithMessageException();
return 1234;
}
The generated code mixed the exception handlers with the hot-path code. Here are the address ranges of relevant chunks: 100401080 - Hot path of exitWithMessageException
100401099
10040109a - Cold path of exitWithMessageException
10040113f
100401140 - Start of mainGCC 9 [1] instead moves the exception throwing branch into a cold clone of exitWithMessageException function. The behaviour seems to have changed on starting from GCC 8.x.