Can any of you explain what the differences are between throw, throws and Throwable and when to use which?
throw
throws
Throwable
throws : Used when writing methods, to declare that the method in question throws the specified (checked) exception.
As opposed to checked exceptions, runtime exceptions (NullPointerExceptions etc) may be thrown without having the method declare throws NullPointerException.
throws NullPointerException
throw: Instruction to actually throw the exception. (Or more specifically, the Throwable).
The throw keyword is followed by a reference to a Throwable (usually an exception).
Example:
1.4m articles
1.4m replys
5 comments
57.0k users