what is difference between throw and throws in exception?

Answer Posted / ishan gupta

Whenever We Handle the exception through THROW we used to write
a handler for handling that Exception that is "CATCH BLOCK".It is done Explicitly by The programmer
EX:-
public static void main(String[] args) {

int a=4;
int b=0;
int c=0;
try
{
c=a/b;
throw new ArithmeticException();
}
catch(ArithmeticException o){
System.out.println("Exception Catched");
}

}

Whenever We Handle the exception through THROWS than We are not worriyng about handling the Exception As this work is done by the JVM
Ex-

public static void main(String[] args)throws ArithmeticException {
int c=4/0;

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is finalize()? Is finalize() similar to a destructor?

546


What are serialization and deserialization?

730


Can we instantiate interface in java?

675


Can inner class extend any class?

600


How do you achieve polymorphism in java?

523






What is an array length?

501


What are register variables what are the advantages?

452


What is the difference between sop and work instruction?

487


Is java 9 released?

527


State some situations where exceptions may arise in java?

629


Is arraylist an object in java?

603


What does java ide mean?

643


What is return code?

561


What is the purpose of a transient variable?

588


How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

546