Announcement Announcement Module
No announcement yet.
Proper exception handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by constv View Post
    For example, "Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)"

    "Redeclaring" exposes the implementation details (in the form of that specific exception) of the underlying module to the modules that should not be otherwise even aware of that module. As the result, when that signature changes (a new exception is added) - you have a domino effect.
    This is why checked exceptions are suitable only for situations that have some meaning for the application (typically some business meaning), some meaning that needs to be part of the contract. In which case it just can not stay "implementation detail". The rule formulated in my previous post was formulated on premise that checked exception are properly designed. It is absolutely obvious that if checked exception represents some implementation detail or technicality (which constitutes design bug) it should be caught and re-thrown as RTE. And in case of a contract change domino effect is rather desirable.

    So full policy is as follow - if you met checked exception:
    • if you can handle it "to the point", handle it
    • if exception is appropriate (has sense as part of the method contract) do not catch it, but redeclare it (really, it should be declared already)
    • if it represents implementation detail or pure technicality - wrap in RTE and re-throw

    Here's link to the famous interview with Anders Hejlsberg (chief architect of C#) where the subject is discussed in more detail (specifically, re-throwing issues, etc.). You probably have seen it, but just in case:
    Yes, I know it. Should admit that C# in many (not all) aspects is better language then Java. But, as for me, it goes in wrong direction now, but that completely different matter.
    Last edited by al0; Apr 17th, 2009, 11:03 AM. Reason: Some rewording to clarify meaning


    • #17
      If anyone want to know proper exception handling then do the search in google and exception handling you get so much of help from there. Most of exception handling is done in SQL, .Net, Oracle Database..