Declare or Catch in Java Programming
when we don't want to handle the particular exception /exception is such type that it woud,nt handle
we declare it
Catch is vice -versa of declare we can handle exception in catch block.
Declare use where exception is not handled
in below example
a class market is declared ,public void purchase is used to purchase the book , but if is not present in the market
than it is must that book will not found in the market so the declaration is used .public void purchase throws booknotfound
Catch is used where exception would be handled
in case there are possibilities of meeting boos in the market it just out of stock
therefore it could be find on another shop .therefore catch block is used .there
are chances of getting.
Declare syntaxclass Market
public void purchase throws booknotfound
//so this is called the declare rule
catch(Bookoutofstoreexception e or BookinstoreException e)