• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling,

 
Mike Wang
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A debate has rised in theserverside about Exception handling
orignal source
http://www.manageability.org/blog/stuff/exception-debate-gosling-hejlsberg-both-wrong
because:
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html?page=1
the debate:
http://www.theserverside.com/home/thread.jsp?thread_id=22547
After read about debates and article,
I have some questions:
should we implement the exception class hierarchy in SCJD(I am doing URLBird)to avoid the so called "scalability of throws clauses" problem.
the detailed design:
the system has a based Exception class, such as UrlBirdException.
also: it has
base exception class DataException which extends UrlBirdexception in DB layer
base exception class BusinessException which extends UrlBirdexception in business logic layer
base exception class UIException which extends UrlBirdexception in UI client
all Exception that might throw should implement the proper exception class in proper layer. such as DuplicateRecord in DB layer should implement DataException...
sounds good, but some how excessive-design and redundancy
your comment, please.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
I struggled over this myself and I am still struggling - even though I am
done. For me, Bruce Eckerel made it a debate back in August when he published his thoughts in Thinking in Java via his website. I searched
everywhere for sometype of answer or good solution. I mean I really
searched. But found nothing that satisfied me. And after reading
the articles you posted you probably want to scream given the
exceptions we must work with in the project given to us by Sun.
My final conclusion was to bite the bullet and use exceptions the
way the sun graders will want to see them. So I basically just
throw what they told me to throw and caught them in the gui controller
class (I tried to catch every exception in the same place).
They all derived from exception which was a requirement. My only deviation from this is I made a class called DatabaseUsageException that is a runtime error that is wrapped around all of million IOExceptions I came across.
This came in handy in that it chained the IOException and allowed me to
throw an exception from methods that sun provided where I could not
change the method signatures, thus the exceptions they threw.
For example the Update method you may write to the file so you have to catch IOExcetpion. Instead of catching and dealing with it in my Data class I wrapped it in a DatabaseUsageException and threw it.
enough of my jabbering...good luck in finding an elegant solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic