Difference Between throw and throws Keyword in Java
In my previous post on java , I have explained about throw keyword here and throws keyword in ja. Furthermore I will discuss the difference between the two keywords in java.
Besides the both serve different purpose. The difference table is given below:
|1||throw is used to create a new Exception object and throw it||It is used in method definition to declare that a risky method is being called and
the method may throw the specified Exception.
|2||Using throw we can only throw one Exception type||using throws we can declare multiple Exceptions|
|3||Example-throw new IOException (“Can not open Connection”);||Example- throws IOException,ArrayIndexBoudException|