I came across this question recently - What is function try block handler?
Also, where would it be useful?
I came across this question recently - What is function try block handler?
Also, where would it be useful?
Here you can find a good explanation.
It could be useful in an initialization list of a constructor:
struct A
{
private:
std::string s;
public:
A( int value ) try : s( boost::lexical_cast<std::string>( value ) ) {}
catch ( boost::bad_lexical_cast ) { /* handle lexical_cast exception here */ }
};
a function written like this:
void fun ()
try
{
.....
.....
}
catch(SomeException & e)
{
....
....
}
is called a function try block.
This is typically used with constructors with initialization lists to catch the exception thrown during the construction of an object constructed in the initialization list.