KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm wondering when programmers use function try blocks. When is it useful? void f(int i) try { if ( i < 0 ) throw "less than zero"; std::cout << "greater than zero" << std::endl; } catch(const char* e) { std::cout << e << std::endl; } int main() { f(1); f(-1); return 0; } Output: (at ideone ) greater than zero less than zero EDIT: As some people might think that the syntax of function defintion is incorrect (because the syntax doesn't look familiar), I've to say that no its not incorrect. Its called function-try-block. See ยง8.4/1 [dcl.fct.def] in the C++ Standard.
Tags (comma-separated)
Save Edits
Cancel