what is difference between throw and throws in exception?
Answer Posted / parveen
throw:the throw keyword is used to throw the exception
manually,that is when you feel a particular line in your
code, when executed is capable of having some exception then
you use throw keyword as:
throw new MyException(arguments if any);
this leads to instantiating of the MyException class and
exception is thrown
throws: this is to be used when you are not using the try
catch statement in your code but you know that this
particular class is capable of throwing so and so
exception(only checked exceptions).in this you do not use
try catch block but write using the throw clause at
appropriate point in you code and the exception is thrown
to caller of the method and is handeled by it. eg:
void trouble()throws IOException,any other exceptions just
separate them with commas.......
{
/* throw statement at appropriate step,
no need to use try catch here,exception would be thrown
to caller and u should provide try catch block to handle
exception there else this process cotinues further till
appropriately it is handeled or prog terminates abruptly */
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is number data type in java?
What is the difference between abstraction and encapsulation?
What is join () in java?
What is maximum size of arraylist in java?
How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
Is java a digit method?
What's the difference between an abstract class and interface in java?
Explain about automatic type conversion in java?
What is string length in java?
explain the difference between jdk and jvm?
What is the difference between double and float variables in java?
make a method which any number and any type of argument and print sum of that arguments.....
What does exclamation mean in java?
What is the functionability stubs and skeletons?
How would you format a date in java? I.e. In the ddmmyyy format?