John Bailo wrote:
how come I can say:
if() statement; else statement;
but I cannot say
try statment; catch() statement;
I always have to use {}
I've wondered about that, too. Seems like a fairly large
inconsistency, and one that grates every time I write a one statement
catch or finally block. Just makes the code take more screen space.
Laziness seems the most likely answer. My best guess is that somehow
it's significantly easier to create the try table (in the metadata)
and to emit the special leave instructions when you have the { and }
tokens as a trigger than if you have to do this for a simple
statement.
But I suppose it's also possible that 'try statement catch
exception-block' creates some parser ambiguities that 'try
compound-statement catch exception-block' does not. I haven't actually
looked at a formal grammar for C# ....
--
www.midnightbeach.com