On Monday, 29 April 2013 at 11:50:11 UTC, Henning Pohl wrote:
On Monday, 29 April 2013 at 11:32:33 UTC, monarch_dodra wrote:
I'm still worried about what it means for a pure function to
throw... (I'm thinking about the "enforce(malloc)" scheme)
If malloc returns null, we are out of memory. In D this is not
an exception, it is an error. So I guess we just need to check
the pointer returned by malloc and throw an OutOfMemoryError on
failure. Thus if the ctor called is nothrow, it can be marked
as nothrow, too.
So in this case, there should be no problem making it pure.
I've hit this issue before: In D, if the *managed* memory runs
out, then it is an error (since then *everything* crumbles:
arrays, GC. etc). The reason it is an error is that since the
memory is managed by the language, there is nothing the user can
do anyway, so throwing is pointless.
for unmanaged memory, on the otherhand, the user *can* do
something about it, so throwing is better.
I myself am not sure I 100% agree with this, but that was the
conclusion last time I tried to transform an malloc=>Exception
into a malloc=>Error+Nothrow