Function with try/catch and no return statement

Stewart Gordon smjg_1998 at yahoo.com
Sun Feb 7 06:54:43 PST 2010


Michel Fortin wrote:
<snip>
> That should be filled as a bug.

Technically it isn't a bug: the rule in the spec is

http://www.digitalmars.com/d/1.0/statement.html#ReturnStatement
"At least one return statement, throw statement, or assert(0) expression 
is required if the function specifies a return type that is not void, 
unless the function contains inline assembler code."

However, I do think it ought to be instead

"At least one return statement is required if the function specifies a 
return type that is not void, unless all possible paths through the code 
lead to a throw statement or assert(0) or the function contains inline 
assembler code."

Additionally or alternatively, one could add a further restriction: "At 
least one return statement [...] that is not within a catch or 
scope(failure) block is required"...

Stewart.



More information about the Digitalmars-d mailing list