• Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet Exceptions

 
Sirisha Reddy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont understand logistics of wrapping any exception into a ServletException. Doesnt it violate polymorphism rules?
How can the SQLException be wrapped into a ServletException when both are subclasses of Exception class?
Thanks,
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will find that the relationship is "has-a", not "is-a" in this case. The ServletException "has-a" SQLException wrapped up in a payload to be delivered by the ServletException when it is caught.
 
Sirisha Reddy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.
The word 'wrapping' confused me, i guess.
We pass SQLException object to a Throwable reference in ServletException constructor and getRootcause() just returns tht passed object.
Thanks,
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!