newbie problem with nothrow
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 1 11:05:49 PDT 2016
On 11/1/16 12:24 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Tuesday, November 01, 2016 12:19:11 Steven Schveighoffer via Digitalmars-
> d-learn wrote:
>> On 11/1/16 11:54 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
>>> On Tuesday, November 01, 2016 10:57:38 Steven Schveighoffer via
>>>> Is there not some assumeNoThrow wrapper somewhere?
>>>
>>> Someone added assemWontThrow to std.exception semi-recently, but I'd be
>>> very surprised if it didn't incur performance overhead such that I'd
>>> just as soon use an explicit try-catch and be done with it.
>>
>> The function I'm imagining shouldn't add any overhead...
>
> assumeWontThrow uses lazy to do what it does (and I'm not sure that there's
> any other way to do it other than string mixins), and as I understand it,
> lazy isn't exactly efficient. Given that it always calls the resulting
> delegate though, the optimizer may be able to remove the extra cost.
I was thinking something like this:
auto assumeNoThrow(alias foo, Args...)(Args args) nothrow
{
try
{
return foo(args);
}
catch(Exception e)
{
throw new Error("foo should not have done that!");
}
}
-Steve
More information about the Digitalmars-d-learn
mailing list