Instead
int tmp; try { tmp = might_throw(); } catch (...) { } const int value = tmp;
You can do it:
int int_value() { try { return might_throw(); } catch (...) { return the_something_value; } } int main() { int const value = int_value(); }
Or, in C ++ 11 you can do
int main() { int const value = []() -> int { try { return might_throw(); } catch (...) { return the_something_value; } } (); }
Cheers and hth. - alf
source share