Why do try..catch blocks require braces?

前端 未结 3 1601
深忆病人
深忆病人 2021-02-11 13:32

While in other statements like if ... else you can avoid braces if there is only one instruction in a block, you cannot do that with try ... catch blocks: the compiler doesn\'t

3条回答
  •  梦如初夏
    2021-02-11 13:56

    Not sure why, but one benefit is that there is no dangling-catch issue. See dangling-else for an ambiguity that can arise when braces are optional.

提交回复
热议问题