FEATURE REQUEST : try...[except]...[finally]...[except]...end;
Original Reporter info from Mantis: el__es
-
Reporter name: Lukasz Sokol
Original Reporter info from Mantis: el__es
- Reporter name: Lukasz Sokol
Description:
Discussed on FPC-general m/l with Sven Barth (and he liked it to the point of convincing me to add this to Mantis) on and about 13/02/2013 in thread 'Fpc Access Violation if AppConfigDir doesn't exist.'
Create a 'packed'/generalized try..[except]...[finally]...[except]...end; construct.
With either side [except] being optional, the full-fledged
try
[code]
except
[except_code1]
finally
[finally_code]
except
[except_code2]
end;
should have the same semantics as
try
try
try
[code]
except
[except_code1]
end;
[code_hole1]
finally
[finally_code]
end;
[code_hole2]
except
[except_code2]
end;
Per Sven's words:
"
The idea for the construct is to replace (if I take your last example) the following construct:
=== example begin ===
try
try
try
except
end;
finally
end;
except
end;
=== example end ===
The variant
=== example begin ===
try
finally
except
end;
=== example end ===
would replace
=== example begin ===
try
try
finally
end;
except
end;
=== example end ===
and
=== example begin ===
try
except
finally
end;
=== example end ===
would replace
=== example begin ===
try
try
except
end;
finally
end;
=== example end ===
These are the most common usages of nested try...finally/except blocks and thus can increase the readability. Thus no change in semantics, only in "formatting".
"
Steps to reproduce:
Traditional approach would require nesting try...except...end; within try...finally...end; multiple times, which can create problems with :-
- adding another 'except' or 'finally' level: if indentation wouldn't change automatically, there can be confusion as to which 'finally' corresponds to which 'try' and 'end' especially if function body is already large [more than 1 screen can fit, for whatever reason]
- protection against cases in which after adding another 'finally' or 'except' nested, some code may be omitted - see hole1 and hole2.
It's not supposed to replace the traditional ways of nesting try..[except,finally]..end; but rather to be used as a handy helper of 'not having to remember how many levels did we nest and where';
Mantis conversion info:
- Mantis ID: 24216
- Monitored by: » ggeldenhuys (Graeme Geldenhuys)