So,how do we know that some method throws an exception that we have to catch? Just as a method must specify what type and how many arguments it accepts and what is returned,the exception that a method can throw must be specified.the list of thrown exceptions is part of a method's public interface.The throws keyword is uned as follows to list the exceptions that a method can throw:void myFuntion() throws MyException1,MyException2{ //code for the method here }
Just as a method must specify what type and how many arguments it accepts and what is returned,the exception that a method can throw must be specified.the list of thrown exceptions is part of a method's public interface.The throws keyword is uned as follows to list the exceptions that a method can throw:void myFuntion() throws MyException1,MyException2{
//code for the method here
}