throw Java Keyword

The throw keyword is used to raise an exception.

Examples

  import java.io.IOException;
  
  public class MyClass
  {
     public method readFile(String filename) throws IOException
     {
        <statements>
        if (error)
        {
           throw new IOException("error reading file");
        }
     }
  }
  

Remarks

Related Topics

catch Java Keyword

finally Java Keyword

throws Java Keyword

try Java Keyword