Why do try..catch blocks require braces?

Straight from the C++ spec:

try-block:
    try compound-statement handler-seq

As you can see, all try-blocks expect a compound-statement. By definition a compound statement is multiple statements wrapped in braces.

Have everything in a compound-statement ensures that a new scope is generated for the try-block. It also makes everything slightly easier to read in my opinion.

You can check it yourself on page 359 of the C++ Language Specification

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)