On 2008-12-02 07:13:12 -0500, Walter Bright <[EMAIL PROTECTED]> said:

I asked this over on stackoverflow.com to see what people using other languages have to say, as well as the D community. The reason I ask is to see if memory allocation can be allowed in functions marked "nothrow".

http://stackoverflow.com/questions/333736/is-out-of-memory-a-recoverable-error

I think you got the question wrong. My answer would be: it depends.

I think you could make this simple reasonable rule: anything that would throw an exception in a nothrow function yeilds a fatal error. When you want to catch out of memory errors (or any other error for that matter), just avoid nothrow.

How does that sound?

It sounds to me like nothrow functions are going to be dangerous in big applications since it could make some distant part of an app crash the whole thing. At least, you should be allowed to handle those exceptions (out of memory, range error, etc) in an error handler function before it kills the current thread. But even with that it'll be hard to guarenty proper cleanup; that's why I'm saying it makes nothrow dangerous.

Note however that you can't guarenty proper cleanup either in case of division by zero or invalid pointer dereferencing, so by allowing dynamic allocation you're not extending the problem very much. It'd be great if those could throw exceptions when not in a nothrow function.

--
Michel Fortin
[EMAIL PROTECTED]
http://michelf.com/

Reply via email to