Trailing catch on function?

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 6 20:30:40 PST 2016


Hey people, I'm passing lots of D function pointers to C, and naturally,
the C api expects the fp signatures are all nothrow.

Which means, my D functions all look like this:

void callback() nothrow
{
try
{
...lots of code...
}
catch (Exception e)
{
...log error or abort...
}
}


I'm generally annoyed by all the extra indentation.
Since nothrow is a central thing in D, I wondered if it would be reasonable
to allow a nice little bit of sugar to assist working with nothrow that
would look like this:

void catchingCallback() nothrow
{
...lots of code...
}
catch (Exception e)
{
...log error or abort...
}

Syntactically similar to the existing in/out sections, although I think it
would be nicer at the bottom...
It's simply a lowering which wraps the entire function body scope in a try.

It's not a really big deal, but it would feel a whole lot tidier in my
existing code.
I don't imagine how it would really affect anything else.

Terrible idea?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20161107/b3647aa6/attachment.html>


More information about the Digitalmars-d mailing list