When an exception is thrown by a method, it must declare or handle it.A method can declare the exception using the keyword throws with the method signature and a list of exceptions type so that the calling methods can guard themselves.
For example:
public void myMethod() throws IOException, ArithemeticException{//some code here that might cause the exception}If a method does not declare the exception then it must handle the exception by providing the try/catch block.For example:public void myMethod(){try{//some code here that might cause the arithematic exception}catch(ArithematicException e){}}
When an exception is thrown by a method, it must declare or handle it.A method can declare the exception using the keyword throws with the method signature and a list of exceptions type so that the calling methods can guard themselves.
For example:
public void myMethod() throws IOException, ArithemeticException{//some code here that might cause the exception}If a method does not declare the exception then it must handle the exception by providing the try/catch block.For example:public void myMethod(){try{//some code here that might cause the arithematic exception}catch(ArithematicException e){}}