The throw keyword is used to raise an exception.
import java.io.IOException;
public class MyClass
{
public method readFile(String filename) throws IOException
{
<statements>
if (error)
{
throw new IOException("error reading file");
}
}
}
The throw statement takes a java.lang.Throwable as an argument. The Throwable is propagated up the call stack until it is caught by an appropriate catch block.
Any method that throws an exception that is not a RuntimeException must also declare the exceptions it throws using a throws modifier on the method declaration.