Consider the following code:
#include
#include
void foo()
{
throw std::runtime_error(\"How long do I live?\");
}
int
A thrown exception is not a temporary - the compiler-generated exception code keeps a permanent copy of it. So you can bind it to a non-const reference.
[edit] I just check the standard and it actually refers to a temporary copy. However, the lifetime of the temporary is guaranteed to be at least as long as that of the exception handler.