throw Java Keyword

Ads
 

throw Java Keyword

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

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

throw Java Keyword

     

"throw " 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 throw keyword in java programming language is used to throw an exception.
-- The throw statement in java programming language takes the object of the class  java.lang.Throwable as an argument. This Throwable is propagates up the
call stack till it is caught by an appropriate catch block lying among the multiple catch blocks.
-- If any method throws an exception which is not a RuntimeException, then it must be declared in advance to handle the exceptions it throws using a throws modifier on the method declaration.

import java.io.IOException;

public class Class1{

public method readtheFile(String file) throws IOException{

<statements>
<statements>
<statements>
 

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

}}
 

Ads

Ads