throws Java Keyword

throws " is a keyword defined in the java programming language.

throws Java Keyword

throws Java Keyword

     

throws " is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the throw keyword indicates the following :

-- The throws keyword in java programming language is applicable to a method to indicate that the method raises particular type of exception while being processed.
-- The throws keyword in java programming language takes arguments as a  list of the objects of type java.lang.Throwables class.
-- when we use the throws with a method it is known as ducking. The  method calling a method with a throws clause is needed to be enclosed within the try catch blocks.

Example to use the throws keyword in a class:

import java.io.IOException;

public class Class1{

public method readingFile(String file) throws IOException{

<statements>

if (error){

throw new IOException("error reading file");
  }
   }
}