suggestion: finally for return values

Stewart Gordon smjg_1998 at yahoo.com
Sun Dec 10 05:03:48 PST 2006


Dan wrote:
> How about modifying D to accept a finally clause for use with function/method
> return values.  For example:
> 
> int foo(int a, double b) {
>   try {
>     ...
>     return num;
>     ...
>   } catch (Exception exc) {
>     ...
>   } finally {
>     ...{statements A}...
>   } finally(int retval) {
>     ...{statements B}...
>   }
> }
> 
> statements B will execute when the try block executes "return num;", passing
> num into the finally clause as "retval".  Whether statements A also executes
> in this case is up for discussion.

What _would_ statements A be for then?  Simply to return something if an 
exception kicks in before the return statement?

I'm not sure about this.  Moreover, the TryStatement syntax already 
suffers from a version of the dangling else problem.  Supporting 
multiple finally clauses might complicate the matter more (not to 
mention break some existing code).

Stewart.



More information about the Digitalmars-d mailing list