Summary:
[Folly] Fix `exception_wrapper::throwException` when called before `main`.
When the `exception_wrapper` is empty, then `throwException` emits a message to `std::cerr` and terminates. If called before `main` begins or after `main` ends, then `std::cerr` might not have been constructed yet or might have already been destructed. Bad. Segfault, etc. So we need to ensure that `std::cerr` is alive by holding an instance of `std::ios_base::Init`.
Reviewed By: Orvid
Differential Revision:
D4576190
fbshipit-source-id:
dd84b5e82eb6bd817d405baf530714e0f4c314c5
} else if (eptr_) {
std::rethrow_exception(eptr_);
}
+ std::ios_base::Init ioinit_; // ensure std::cerr is alive
std::cerr
<< "Cannot use `throwException` with an empty folly::exception_wrapper"
<< std::endl;