# throws Java Keyword

The throws keyword may be applied to a method to indicate the method raises particular types of exceptions.

## 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

- The throws keyword takes a comma-separated list of java.lang.Throwables as an argument.

- 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.

- The caller of a method with a throws clause is required to enclose the method call in a try-catch block.

Related Topics

catch Java Keyword

finally Java Keyword

throws Java Keyword

try Java Keyword