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
Is a method a procedure?
What is locale in java?
How dead lock situation occurs in java and how you can identify it?
When should a function throw an exception?
What is blank final variable?
what is daemon thread and which method is used to create the daemon thread? : Java thread
Can a method inside a interface be declared as final?
Write a program to print fibonacci series
Can we create a class inside a class in java?
Is array an object in java?
What is formatted output?
What is a Hash Table? What are the advantages of using a hash table?
How do you include a string in java?
Can you tell me range of byte?
What's the base class in java from which all classes are derived?