I'm working through a book on C++ and in the chapter on errors it has this program (I left a couple of minor things out but it's mostly this):
int main()
try {
// our program (<- this comment is literally from the book)
return 0;
}
catch(exception& e) {
cerr << "error: " << e.what() << '\n';
return 1;
}
catch(...) {
cerr << "Unknown exception\n";
return 2;
}
This compiled but of course it did nothing so I'm still wondering about
- why there isn't a set of curly braces enclosing everything after main()? Are the blocks or shall I call them "catchphrases" (ha!) part of main() or not?
- If they are functions how come there's no "int" before catch(whatever)?
- If they're not functions, what are they?
- re catch(...), I've never seen ellipses used that way. Can I use ellipses anywhere to mean "anything"?