www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Throw in a pre-condition of a nothrow function

reply "bearophile" <bearophileHUGS lycos.com> writes:
Currently this code compiles:


void foo() nothrow
in {
     throw new Exception(null);
} body {
}
void main() {
     foo();
}



Then at runtime throws:

object.Exception test.d(3)
---------
0x00402044 in nothrow void test.foo() at ...
...


Is this good? Isn't the "nothrow" tag used by the compiler to 
better optimize functions?

Bye,
bearophile
Mar 08 2013
next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
That's a bug. Interesting point here is whether it is a 
regression or not.
Mar 08 2013
prev sibling parent reply "Rob T" <alanb ucora.com> writes:
On Friday, 8 March 2013 at 19:39:47 UTC, bearophile wrote:
 Currently this code compiles:
[...] Nice edge case to test the compiler with. Definitely looks like a bug. It should not compile given the nothrow attrib. If it was throwable, what to do about throwing a null reference is an interesting question. --rt
Mar 08 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Rob T:

 Definitely looks like a bug. It should not compile given the 
 nothrow attrib.
http://d.puremagic.com/issues/show_bug.cgi?id=9669 Bye, bearophile
Mar 08 2013