"Jonathan M Davis" <[email protected]> wrote in message
news:[email protected]...
> On Sunday, February 19, 2012 16:59:49 Daniel Murphy wrote:
>> "Nick Sabalausky" <[email protected]> wrote in message
>> news:[email protected]...
>>
>> > The only problem I've ever had with them is that there's no templated
>> > catch blocks, so you can't handle two different exceptions with the
>> > same
>> > code without violating DRY or worse: catching the common base type and
>> > rethrowing when it's not what you wanted. Toss in templated catch
>> > blocks,
>> > and I've have no problem at all.
>>
>> Do you mean something like this?
>> try
>> {
>> something();
>> }
>> catch (e : ThisException, ThatException, OtherException)
>> {
>> static assert(is(typeof(e) == CommonType!(ThisException,
>> ThatException,
>> OtherException));
>> }
>> catch (Exception e)
>> {
>> // Every other type derived from Exception
>> }
>>
>> Or do you think the full power to be able to template catch blocks as if
>> they were functions would be useful for something?
>
> I think that being able to have a catch block which took multiple
> exception
> types would be plenty. There are times when it would be very valuable to
> be
> able to use the same catch block for multiple exceptions without having to
> catch their base type (which would then potentially catch other exceptions
> which you didn't want to catch). So, something like that second catch
> block
> that you have there would be very valuable.
>
> - Jonathan M Davis
I assume you mean the _first_ catch block?
By the looks of it java 7 has this with an awful syntax.
Maybe we should introduce implicit 'catch fallthrough':
void fun()
{
try { something; }
catch (ExceptionA) {} // falls through implicitly
catch (ExpcetionB)
{ // handle both A and B
break;
}
catch (ExceptionC)
{
// handle exception C
break;
}
}