Fix exception_wrapper::throwException when called before main
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 17 Feb 2017 05:07:49 +0000 (21:07 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 17 Feb 2017 05:23:07 +0000 (21:23 -0800)
commit05499631dc3e1160d673a7dd57e70fc797e532dc
tree3b7149aab1546419be007e6b8ee3840663d4fdc0
parent1d804f037c302280d3d89ac408056ea3cfe7989f
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
folly/ExceptionWrapper.cpp