August 08, 2013 Re: What's the D way of allocating memory? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Thursday, 8 August 2013 at 18:35:06 UTC, Gary Willoughby wrote: > calloc is marked as nothrow but apparently throws OutOfMemoryError on allocation failure? ..eh? O_o http://dlang.org/function.html Nothrow Functions: Nothrow functions do not throw any exceptions derived from class Exception. Error is not Exception (they are both Throwable though), Errors are considered non-recoverable and leaving program in invalid state. They are allowed even in nothrow functions. |
August 08, 2013 Re: What's the D way of allocating memory? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Thursday, 8 August 2013 at 18:53:02 UTC, Dicebot wrote:
> On Thursday, 8 August 2013 at 18:35:06 UTC, Gary Willoughby wrote:
>> calloc is marked as nothrow but apparently throws OutOfMemoryError on allocation failure? ..eh? O_o
>
> http://dlang.org/function.html
> Nothrow Functions:
> Nothrow functions do not throw any exceptions derived from class Exception.
>
> Error is not Exception (they are both Throwable though), Errors are considered non-recoverable and leaving program in invalid state. They are allowed even in nothrow functions.
Ah right thanks.
|
August 10, 2013 Re: What's the D way of allocating memory? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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 |
Copyright © 1999-2021 by the D Language Foundation