Discussion Thread: DIP 1029--Add throw as Function Attribute--Final Review
NaN
divide at by.zero
Sat Apr 18 16:28:59 UTC 2020
On Saturday, 18 April 2020 at 12:03:46 UTC, Jacob Carlborg wrote:
> On 2020-04-17 13:28, Mike Parker wrote:
>> This is the discussion thread for the Final Review of DIP
>> 1029, "Add throw as Function Attribute":
>>
>> https://github.com/dlang/DIPs/blob/9db80ddadcf5a220958ddcfec14b9c71cdb43d1c/DIPs/DIP1029.md
>
> I would like to see the "throw" keyword being used as an
> attribute to implement something like "Zero-overhead
> deterministic exceptions: Throwing values" [1].
>
> I imagine it looking something like this:
>
> enum CopyError
> {
> permissionDenied
> }
>
> void copy(string src, string dest) throw(CopyError)
> {
> throw CopyError.permissionDenied;
> }
>
> void main()
> {
> try
> copy("foo", "bar");
> catch (CopyError e)
> writeln(e);
> }
>
> Which would be lowered to something like the equivalent of the
> following code:
You could have the caller pass an alternate return address to the
callee. So...
void copy(string src, string dest, void* err)
{
if (somethingbad) { EAX = errorcode; RET (to) err; } ***
}
void main()
{
auto result = copy("foo", "bar", &L1);
return;
L1: writeln("Oh noes!");
}
*** So all the callee has to do is poke the alternate return
address into the stack and RET as normal. (On x86 at least).
More information about the Digitalmars-d
mailing list