What's the D way of allocating memory?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Aug 8 11:45:40 PDT 2013
On Thu, Aug 08, 2013 at 08:35:04PM +0200, Gary Willoughby wrote:
[...]
> calloc is marked as nothrow but apparently throws OutOfMemoryError
> on allocation failure? ..eh? O_o
nothrow means Exception objects won't be thrown.
OutOfMemoryError is a Throwable, but not an Exception, so it is excepted
from nothrow. The idea is that these Throwable Errors are serious
runtime failures that indicate the program must terminate.
It's a very bad idea to catch an Error unless you know what you're
doing. And even then, you cannot safely resume program execution because
the fact that it can get thrown from nothrow functions means that some
cleanup code may have not been executed (nothrow functions do not
register stack unwinding handlers), so your program is potentially in an
inconsistent state. The only sane thing to do upon catching an Error is
to perform any last-ditch backups of important data, then terminate the
program.
T
--
The best compiler is between your ears. -- Michael Abrash
More information about the Digitalmars-d-learn
mailing list