Function Try Block for regular function
suggest changevoid function_with_try_block()
try
{
// try block body
}
catch (...)
{
// catch block body
}
Which is equivalent to
void function_with_try_block()
{
try
{
// try block body
}
catch (...)
{
// catch block body
}
}
Note that for constructors and destructors, the behavior is different as the catch block re-throws an exception anyway (the caught one if there is no other throw in the catch block body).
The function main
is allowed to have a function try block like any other function, but main
’s function try block will not catch exceptions that occur during the construction of a non-local static variable or the destruction of any static variable. Instead, std::terminate
is called.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents