News for hackers. Stuff that matters.
Re:Don’t Use Try/Catch (2010) by gweinberg on Saturday December 28, 2013 @01:30PM (#6975680)
I used to use try/catch with an empty catch block in Java all the time. The exception could never in fact occur, but the compiler required me to either add a catch block or declare that my function raises an exception, when it fact it doesn't.

Yes, I did include a "this never happens" comment. That is my favorite comment, but only if it is true.

Re:Don’t Use Try/Catch (2010) by wheaties on Saturday December 28, 2013 @01:37PM (#6975711)
Ah, it was people like you who did this even when, as you said it should never happen, that caused me many a late night... 'cause it did and that empty catch block hid it.

Don't leave empty catch blocks. At least put in some form of logging of the exception, just in case.

Re:Don’t Use Try/Catch (2010) by Mindless2112 on Saturday December 28, 2013 @01:39PM (#6975714)
The most common code I write in C# is in switches on enums:

   default:
     throw new InvalidOperationException("Should never happen!");
Re:Don’t Use Try/Catch (2010) by gst on Saturday December 28, 2013 @02:22PM (#6975969)
Why don't you just throw a runtime exception inside the catch block?
Re:Don’t Use Try/Catch (2010) by alecdbrooks on Saturday December 28, 2013 @01:46PM (#6975743)
My thought would be to add an assertion that always fails inside the catch block, but this probably only makes sense if you use assertions already, as they have to be turned on explicitly in Java.
Re:Don’t Use Try/Catch (2010) by buerkle on Saturday December 28, 2013 @01:47PM (#6975746)
Years ago I found the source of my troubles which took longer than it should have because Tomcat had an empty catch around InterruptedException with a "this will never happen" comment.