Error: cannot return non-void from void function

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 27 09:26:21 PST 2014


On Thu, 27 Nov 2014 17:22:35 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> 
> > ah, that's it! as spec says, D determines function return value 
> > from
> > the first 'return' statement it seen. in your case this is 
> > `return;`,
> > so function return type is determined to be `void`.
> >
> > if you doing `auto` functions, try to arrange your code so the 
> > first
> > `return` returning the actual value.
> >
> > besides, your code is wrong anyway, 'cause you can't have 
> > function that
> > returns both "nothing" and "something". your first `return;` 
> > should
> > either return something, or must be changed to throwing some 
> > exception.
> 
> How I can terminate program? First return I used to terminate app 
> if config file is exists.
throw an exception. uncatched exception will terminate your program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141127/9976b305/attachment.sig>


More information about the Digitalmars-d-learn mailing list