Implicit try scope when catch or finally block is given #908
Replies: 2 comments 1 reply
-
I much prefer the explicitness of having the |
Beta Was this translation helpful? Give feedback.
-
If your method is long enough that the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It's not unusual for a method to contain a
try/catch/finally
that spans the whole method definition, like so:This proposal would allow eliding the
try
and its braces (onlycatch
is shown, butfinally
would be treated identically):Explicit
try
blocks would of course still be available, and the presence of one would limit the scope in which thecatch
would apply, just as it works today. The following would likely not be allowed, but I'd be interested to hear feedback:Specifically, when there's no statement between the earlier catch block and the method-level catch block, there would be a syntactic conflict with the already-existing multiple catch blocks feature, and if you're writing this kind of code you probably want maximum clarity about what can be caught where. But the simple case (with no other
try/catch
in the same scope) would cut down on boilerplate without sacrificing clarity.Beta Was this translation helpful? Give feedback.
All reactions