Commit 05499631 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix exception_wrapper::throwException when called before main

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
parent 1d804f03
......@@ -26,6 +26,7 @@ namespace folly {
} 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment