Home Help Java T throws Java Keyword
Questions:Ask|Latest



throws Java Keyword
Posted on: November 18, 2009 By Deepak Kumar
throws " is a keyword defined in the java programming language.

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");
  }
   }
}


Recommend the tutorial

Ask Questions?    Discuss: throws Java Keyword   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
udaykumar
November 16, 2011
throw and throws is a keyword or class?

pls give reply
Sriram
March 5, 2012
Java

What is the main use of throw & throws keywords in java..?