Timeline for In C#, why are variables declared inside a try block limited in scope?
Current License: CC BY-SA 3.0
4 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 16, 2020 at 10:01 | history | edited | CommunityBot |
Commonmark migration
|
|
Jul 21, 2017 at 12:26 | comment | added | Pete Kirkham | "when you write code in a try block with catch clauses, you are telling both the compiler and any human readers that it should be treated like it might not all be able to run." What the compiler cares about is that control can reach later statements even if previous statements throw an exception. The compiler normally assumes that if one statement throws an exception, the next statement won't be executed, so an unassigned variable won't be read. Adding a 'catch' will allow control to reach later statements - it's the catch that matters, not whether the code in the try block throws. | |
Jul 20, 2017 at 3:46 | review | First posts | |||
Jul 22, 2017 at 8:50 | |||||
Jul 20, 2017 at 3:43 | history | answered | Eliah Kagan | CC BY-SA 3.0 |