Thursday, September 11, 2008

checked exceptions (good or bad)

C# and Java differ in some aspects. One of it is Exceptions handling. C# does not have checked exceptions while Java does. Is it good or bad? So why are they bad?

People are lazy (I am). Due to checked exceptions, the burden is put on the programmer to think of those checked exceptions that would be thrown and explicitly duck or handle them. Not all would know all of them. It encourages empty catch blocks and that would catch a higher level exception like Exception or IOException and that defeats the purpose of checked exception. If C# had them, empty catch blocks would catch System Exceptions and that is a bad thing (catching Out of Memory exception for example). This was (one of) the reason why checked Exceptions were not included in C# by its chief Architect Anders Hejlsberg. 


[Hat tip to AN]

No comments:

Post a Comment