what difference between throw and throws in exception
handling.

Answer Posted / aravinda reddy

Whenever we want to force an exception then we use throw
keyword,throw keyword can also be used to pass a custom
message to the exception handling module i.e. the message
which we want to be printed. throw we will use at statement
level.

Whereas when we know that a particular exception may be
thrown or to pass a possible exception then we use throws
keyword. Point to note here is that the Java compiler very
well knows about the exceptions thrown by some methods so
it insists us to handle them. Method Level

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are static methods?

808


What are the advantages of inner classes?

741


Why main method is called first in java?

754


Can you call a method on a null object?

767


What are the loops in java?

749


What is main in java?

785


What does nullpointerexception mean?

863


What is difference between Heap and Stack Memory?

749


Write a java program to check if a number is prime or not?

760


What are different types of inner classes ?

782


can I implement my own start() method? : Java thread

750


What is java jit compilers?

759


Can you pass by reference in java?

732


Is there a case when finally will not execute?

777


What is the difference between scrollbar and scrollpane?

825