Why does it not allowed to use try-catch statement without {} ?
- by alex
Why can't I use code like this ?
1
int i = 0;
try i = int.Parse("qwerty");
catch throw;
2
try i = int.Parse("qwerty");
catch;
finally Log.Write("error");
And should write like this
1
int i = 0;
try { i = int.Parse("qwerty"); } catch { throw; }
2
try { i = int.Parse("qwerty");}
catch {}
finally {Log.Write("error");}
PS:
I can use if-else statement without {}. Why should I use them with try-catch(-finally) statement ? Is there any meaningful reason ?
Is it only because that some people think that code is hard to read ?
Several months ago I asked that question on russian programming forum but I got no satisfactory answer ...