0
what is difference between throw and throws
2 Antworten
0
Throws is used to declare an exception and throw is used to throw an exception explicitly. In other words, generally Checked exeptions we use throws and unchecked exeptions throw.
0
Hmm, I think Felipe's answer is not the full story:
throws is used to specify Checked exceptions on function signatures, like this:
public void foo() throws(MyExcept1, MgExcept2) {
...
throw MyExcept1("some msg") ;
You then use throw inside the method body to throw these declared exceptions.
You don't normally throw unchecked exceptions yourself - these are JVM (or OS) generated when bad things happen (like divide by 0/out of memory /etc)