Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranchers

I want to know " is it true method calling another has to declare exception or the called method takes care of it ? is that really "BUCKING" (not talking about handling but just declaring).i am aware of the STACK hierarchy(pardon for spell) but wanted make sure that would it compile or just give an error.

Thanks in advance

--Chintan
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If method2() declares that it throws an exception, then method1() (calling method2()) must catch and handle the exception (or a superclass of the exception) or method1() must declare that it throws the exception (or a superclass of the exception). We say that method1() "passes the buck" or "ducks the exception" if it throws the exception that method2() throws.
 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry's comments are on target except that they only apply to checked exceptions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic