DMD 1.027 and 2.011 releases
eao197
eao197 at intervale.ru
Mon Feb 25 04:26:05 PST 2008
On Mon, 25 Feb 2008 12:44:15 +0300, Walter Bright
<newshound1 at digitalmars.com> wrote:
> Ary Borenszweig wrote:
>> Does this mean this will not compile:
>> int foo(int[] someArray, int someIndex) nothrow {
>> return someArray[someIndex];
>> }
>> but this will:
>> int foo(int[] someArray, int someIndex) nothrow {
>> if (someIndex < someArray.length) {
>> return someArray[someIndex];
>> } else {
>> return -1;
>> }
>> }
>
> I don't know yet. But the idea is to do static checking of what can
> throw.
Just my $0.02 about nothrow and DesignByContract: I think that nothrow are
incompatible with DbC. A function/method could have contracts or nothrow
but not both of them. It is especially actual for virtual (non-final)
methods. Suppose that some class has:
class A {
public void cleanup() nothrow { ... };
}
so it could be safely used in 'finally' statement:
A someResource = acquireResource();
try { ... /* some processing */ ... }
finally {
someResource.cleanup; /* looks like exception-safe action */
}
But if there is a derived class B, which overrides cleanup() with
postcondition:
class B : A {
public void cleanup() nothrow
out { ... some checking ... }
body { ... some actions ... }
}
and acquireResource() would return B instead of A, then the code above
won't be exception-safe. Moreover the behaviour of 'someResource.cleanup'
would depend on compiler switches.
--
Regards,
Yauheni Akhotnikau
More information about the Digitalmars-d-announce
mailing list