• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reason?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can throw exception ourself by using throw keyword???
What is the advantage of throwing exception???
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start reading here: http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine instead of something like "Reason??" when you post a question.
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can throw exception. After throwing an exception you should catch it and provide some exception handling mechanism.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think about the following small program with the following Classes. Father, Mother and Son. Father has method provideBread(double money), mother has method buyBread(double money, Son son)and Son has method goToShop(double money). In order for the family to obtain bread, provideBread() is invoked on Father by passing his money, say 10.0. In turn, provideBread() invokes buyBread() on mother, passing the money and the specific son to send to the shop. The mother, as you would imagine, delegates the business of going to the shop to her Son by calling his goToShop() method. Now, on reaching the shop, several things (Exceptions) may happen. For instance, here may be no bread at the shop or the money passed by Father may not be enough. If the exception is that there is no bread at the shop, the son might very well handle it by checking in the next shop without requiring to inform any of his parents of that decision. In this case, Son Handles the exception, say BreadOutOfStockException. If however the money is not enough, the son will need to inform his mother of that fact (in other words, catch the say, MoneyNotEnoughException and instead of handling it, throw it to his mother). Of course the mother may handle the exception herself (if she is not broke, say broke) or "throw" it higherup to the father for him to worry about where to get more money (How to handle the exception).

Good luck!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad usman shad wrote:We can throw exception ourself by using throw keyword???
What is the advantage of throwing exception???



It depends on what's your opinion on passing around error codes. That's the alternative. What you prefer is up to you.
 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Gitahi!!!
I am impressed with your answer...
Thanks alot...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic