Trailing catch on function?

Manu via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 8 08:04:42 PST 2016


On 8 November 2016 at 12:50, Mike Parker via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Tuesday, 8 November 2016 at 01:50:26 UTC, Walter Bright wrote:
>
>> On 11/7/2016 4:12 PM, Robert burner Schadek wrote:
>>
>>> On Monday, 7 November 2016 at 23:37:18 UTC, Walter Bright wrote:
>>>
>>>> void callback() nothrow
>>>> {
>>>>     scope (failure)
>>>>     {
>>>>         ...log error or abort...
>>>>     }
>>>>     ...lots of code...
>>>> }
>>>>
>>>
>>> Who to get the Exception thrown in the scope(failure)
>>>
>>
>> You don't. The exception is also rethrown, so it isn't an exact
>> replacement. (The 'nothrow' is a mistake on my part.)
>>
>
> In this specific case, a function used as a callback for a C API, it
> really ought to be nothrow because of the inconsistent behavior with
> propagating exceptions across language boundaries. scope(exit) just isn't
> useful here.
>

It's not strictly useful for interaction with C, it would be equally useful
in the situation where a nothrow function returns an error code or
something. The tail-catch block could do the translation and return the
error, and it would be in a nice place separate from the main function body.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20161109/8af34855/attachment.html>


More information about the Digitalmars-d mailing list