Can somebody explain me what is the use of throws Exception in java?
Its just used to indicate that the method will throw the exception specified? The calling method need to catch the exception specified?
So instead of throws we can use a try-catch block to catch the exception?
How it differs from throw?
Thanks
Java uses explicit exception handling – except of
RuntimeExceptions, every exception thrown [by the method itself, or a method it invokes declares itthrowsit]- must be handle or declared in the method signature.It allows safety, since when you invoke a method you know exactly which errors might occur, which you can then either handle locally with
try/catchblocks, or declare as part of your method signature.