Throws and Throw
The topic of exception handling is really baffling me. First of all i would like to know that how will i need to know that my method needs to throw an exception? Secondly what is the difference between throws and throw?
If i may...is throw used when i dont want to use try/catch statement?? and also the exception thrown by my method is my defined by myself?? in other words when the exception is user defined?? correct if am wrong.
sorry by that i meant to say that do we also use throw because we dont want to create the own exception class. this statement of mine "If i may...is throw used when i dont want to use try/catch statement?" is wrong kindly ignore that.
The keyword 'throws' is used in the method header to mention the checked exceptions that can be thrown by this method; there is no need to mention the unchecked exceptions. The 'throw' keyword is used to throw any object that is or extends from the Throwable class.