Can we use throw method without using try in any place of code? and can anyone tell me what is the difference between throw and throws?
Printable View
Can we use throw method without using try in any place of code? and can anyone tell me what is the difference between throw and throws?
Hi,
Yes. You can use throw alone without using try catch.
EG:
public void foo() throws Exception {
throw new Exception();
}
Throw is used to throw an exception.
Throws is used in a method declaration which says that this function throws an exception.
Hope this helps.
Regards,
Sahil.