r/ProgrammerTIL • u/kmatt17 • Feb 24 '19
C++ [C++] TIL about function try-blocks
There exists a bit of syntax in C++ where functions can be written like so:
void TryCatchFunction()
try
{
// do stuff
}
catch (...)
{
// exceptions caught here
}This is the equivalent of:
void TryCatchFunction()
{
try
{
// do stuff
}
catch (...)
{
// exceptions caught here
throw; // implicit rethrow
}
}This has been in the language for a long time yet seems to be quite an unknown feature of the language.
72
Upvotes
View all comments
Show parent comment
18
u/[deleted] Feb 24 '19
Because it's more unnecessary crap for the guy maintaining your code.
It would jump out for no reason every time you read the code, making it easier to miss subtle mistakes in the function itself by diverting part of your attention.
Impress people with substance, not style!