+ 1
what is difference between throw and throws ??
2 ответов
+ 1
throws keyword used to delegate or handle the checked exception which may arise by the compiler to the JVM. when programmer doesn't have any interest to handle the checked exception then he can write throws keyword which means giving control to the JVM itself to handle.
where as throw keyword is used to create our own exception.
Example:
In case of Gmail login if we enter password incorrect then immediately it raises an exception/error saying invalid password. so internally developers will use throw keyword to raise that error/exception,if your entered password doesn't match.
0
throw keyword will use when we want to create our own exception,throws will delegate the exception