• Post Reply Bookmark Topic Watch Topic
  • New Topic

exception propagation  RSS feed

 
abhijeet kush
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please explain why exception propagation is used ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7962
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it's not always appropriate to deal with an exception in the same method that it occurs. Deeper method calls may not have the context required to handle the exception, such as a graphical user interface.
 
Liutauras Vilda
Sheriff
Posts: 4914
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi abhijeet kush,

Because, not necessarily always, method knows how to handle that exception. Sometimes it is better to throw it way up.

Non-Java example:
Lets assume cashier did the mistake on a task, so, not necessarily he knows the best, how to solve that mistake, so he asks person "above" him to solve that - accountant for example.
If accountant doesn't know what to do and how best solve that problem, he goes to his boss, who primarily asked the accountant to do that task.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!