Why foreach is not nothrow even for a simple associative array?

bearophile bearophileHUGS at lycos.com
Thu Oct 13 02:25:29 PDT 2011


Cheng Wei:

> nothrow void test() {
>     foreach(k, v) {
>        printf("%d, %d\n", k, v);
>     }
> }
> Cannot compile with the error:
> 
> Error: _aaApply2 is not nothrow
> 
> It is not so convenient that we have to use try-catch for all
> iteration even when we know that it will not throw at all.

_aaApply2 is the function used to iterate on the associative array. It is not yet tagged with "nothrow" so you can't yet use it in an nothrow function. This is a known bug that is already in Bugzilla and will be fixed. 

I think it's not hard to add those tags, so if you want you will probably be able to create a little pull request that fixes this even if you don't know much about compilers.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list