程序在哪里为抛出对象分配内存?

Where are program allocate memory for throwing object?

如果我从函数 h()

中抛出一些字符串
f()->g()->h()

这样

throw std::string("error");

并且只在 f() 中捕获。程序在哪里为这个字符串分配内存?显然不能分配到h()的栈上。如果这是 f() 的堆栈,它以什么方式知道应该在什么地方分配?

If this is stack of f() in what way it know in what place it should allocate?

这是一个以未指定方式分配的临时对象。

来自标准的 Throwing an exception 部分:

3 A throw-expression initializes a temporary object, called the exception object, the type of which is determined by removing any top-level cv-qualifiers from the static type of the operand of throw and adjusting the type from “array of T” or “function returning T” to “pointer to T” or “pointer to function returning T”, respectively. ...

4 The memory for the exception object is allocated in an unspecified way, except as noted in [basic.stc.dynamic.allocation]. ...