What is the catch or declare rule for method declarations?

Answer Posted / amit2009mca

the catch and decalre rule to handle the exception
1)when we don't want to handle the particular exception
we declare it
means to say that imagine that you go to market class
and call the purchase method to purchase a book.
but the shopkeeper has n't the particular book so its
responsibility to shopkeeper that he inform you about
particular exception so he declare the exception
Booknotfound and throws like this
class Market
{
public void purchase throws booknotfound
{
}
}
so this is called the declare rule

another is
2)catch
imagine you call the purchase method to buy book but there
is some problem like book is tore up or book is in godown
so its peoblenm pf the sopkeeper so its responsibility of
shopkeeper to handle this particular exception
then the Catch rule comes in a ligtht
like theis
class Narket
{
public purchase()
{
try{
}
catch(Booktoreupexception e or BookinstoreException e)
{
}
thanks if you got this because these all are just for
checked exception thanks
AMIT SINGH09(amitsing2008@gmail.com) thanks

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain when noclassdeffounderror will be raised ?

616


What is the full name of java?

565


Why Do I Get A "permission Denied" Error After Downloading The .jnlp Java Launcher For The Vkvm?

622


What restrictions are placed on method overloading?

601


How would you dynamically allocate memory to an array?

591






What is the default size of load factor in hashing based collection?

560


How are java objects passed to a method and what are native methods?

590


What is default locale java?

534


Can we have multiple catch block for a try block?

584


What is difference between Heap and Stack Memory?

534


Explain the difference between map and flatmap stream operation?

817


List some features of the abstract class.

587


What are voids?

530


What is the range of the short type?

580


When is the finalize() called? What is the purpose of finalization?

577