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 .
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
How many types of memory areas are allocated by jvm?
what is encapsulation in java? Explain
Which number is denoted by leading 0x or 0x in java?
Why null value is used in string?
How do you read and print a string in java?
What is the meaning of 3 dots in java?
Does list allow duplicates in java?
What is the difference between and ?
What is array and arraylist in java?
Is java good for beginners?
Why are lists ordered in java?
What is size_t?
What are the benefits of operations in java?
What is a nested list?
What are the two categories of data types in the java programming language?