On 2013-04-02 11:59:39 +0000, Dmitry Olshansky <[email protected]> said:
02-Apr-2013 15:35, Andrei Alexandrescu пишет:
On 4/2/13 7:24 AM, Dmitry Olshansky wrote:
You might want to add Visitor pattern to Exceptions but it's darn messy
to deal with and is an overkill most of the time.
Actually I think that's a good thing to do.
Why would be that? It doesn't solve the key problem of "try clause plus
a ton of semi-identical catches" used just to perform a mapping of X
handlers to Y subsets of errors. Plus visitor does the same dispatch
that is already addressed by exception handlers (or partly so).
What would be nice is some syntactic sugar for the following pattern:
void handler(CommonExceptionType e)
{
// do something with exception
}
try { … }
catch (FooException e) { handler(e); }
catch (BarException e) { handler(e); }
catch (BazException e) { handler(e); }
That could become:
try { … }
catch (CommonExceptionType e in FooException, BarException,
BazException)
{
// do something with exception
}
I've been secretly wishing for something like this, and not just in D.
--
Michel Fortin
[email protected]
http://michelf.ca/