The Right Approach to Exceptions

Jonathan M Davis jmdavisProg at
Sat Feb 18 23:52:00 PST 2012

On Sunday, February 19, 2012 18:44:30 Daniel Murphy wrote:
> I assume you mean the _first_ catch block?

Yes. I should have been more specific.

> 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;
>     }
> }

That wouldn't work, because it would make it so that ignore an exception in 
the middle if you wanted to (much as that's generally bad practice). It would 
also have the problem that you couldn't access the exception itself, and while 
you obviously wouldn't be operating on the exception's exact type regardless, 
you might want to iteract with the functions on a common based class.

So, while at first glance, it seems like a good idea, I think that it has too 
many issues as-is to work. It might be possible to adjust the idea to make it 
workable though. Right now, it's possible to do it via mixins or calling a 
function inside the catch, but doing something similar to this would certainly 
be nice, assuming that we could sort out the kinks.

- Jonathan M Davis

More information about the Digitalmars-d mailing list