Why exceptions for error handling is so important

via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 13 11:42:46 PST 2015


On Tuesday, 13 January 2015 at 00:05:31 UTC, Walter Bright wrote:
> On 1/12/2015 3:17 PM, deadalnix wrote:
>> On Monday, 12 January 2015 at 22:17:57 UTC, Walter Bright 
>> wrote:
>>> Yes, it does. Returning an int in EAX now becomes returning a 
>>> pair [EAX,EDX].
>>
>> It is not that big of a deal, EDX is a trash register anyway 
>> if memory serve,
>> but then, it become very bad when it do not fit in register 
>> anymore.
>
> Returning a slice, for example, already consumes EAX and EDX. 
> Adding an error code pushes that into returning via a pointer 
> to a stack temporary.
>

There are techniques to mitigate that. For example, Rust is smart 
enough to encode the "not-present" state for pointers as a NULL 
pointer (Rust pointers are non-null).

If an error code needs to be returned, it can be encoded as a 
misaligned pointer (if you're feeling adventurous). Don't know 
whether Rust does the latter, though.

Of course, these things have costs of their own.


More information about the Digitalmars-d mailing list