Why does this C++ function definition not require curly braces?

Viewed 265

I was reading Stroustrup's "Programming -- Principles and Practice Using C++" and found that he included a function without the main curly braces without explaining himself and online people say it is impossible.

I have compiled the code and it works totally fine.

void f()
    try {} 
    catch(...) {}

I expect to get a compiler error from this but I do not and it works fine. I am using C++17.

1 Answers

not require curly braces?

There are curly braces:

void f() try {} catch(...) {}
             ^^

This is a Function-try-block:

A function-try-block associates a sequence of catch clauses with the entire function body

Related