Exception Propagation

Throws Keyword in Java with Example

What is throws keyword in Java?

throws keyword is used to declare that a method may throw one or some exceptions. The caller must catch the exceptions.

Suppose in your java program you using a library method which throws an Exception

In your program, you will handle this exception using try & catch.


throw new IOException(“can not open connection”);


throws IOException, ArrayIndexBoundException;


The “Java throw keyword” is used to declare an exception. For any method that will “throw” an exception, it is mandatory that in the calling method, you use throws to list the exception thrown.