+ 1
Is throws and throw are User defined exception??
As throw also create a new exception and when we extend throwable class, then again we can define our exception
1 Antwort
+ 2
By extending a Throwable class, you define own exception type.
Throw statement means that an error occurred and you "send" an exception object from a method (throw it).
class MyExc extends Throwable{}//This only means that there exists some MyExc type.
int mydiv(int a, int b){
if (b==0)
throw new MyExc(); //here an error occurs (we don't allow division by 0), so you want to throw a MyExc object
return a/b;
}