what is difference between throw and throws in exception?
Answer Posted / basant
) throws keyword gives a method flexibility of throwing an Exception rather than handling it. with throws keyword in method
signature a method suggesting its caller to prepare for Exception declared in throws clause, specially in case of checked Exception and provide sufficient handling of them. On the other hand throw keyword transfer control of execution to caller by throwing an instance of Exception. throw keyword can also be used in place of return as shown in below example:
private static boolean shutdown() {
throw new UnsupportedOperationException("Not yet implemented");
}
as in below method shutdown should return boolean but having throw in place compiler understand that this method will always throw exception .
Read more: http://javarevisited.blogspot.com/2012/02/difference-between-throw-and-throws-in.html#ixzz1xaAnuuuu
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which class is the superclass for every class in java programming?
What is the purpose of the System class?
What is meant by structural programming?
Can you extend main method in java?
Difference between serialization and deserialization in java?
Where are local variables stored?
What is an object in java and how is it created?
how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application
Is ruby built on java?
Can we start a thread twice in java?
What are the types of collections in java?
What are java packages? What is the significance of packages?
whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net
What are advantages of exception handling in java?
What is the difference between menuitem and checkboxmenu item?