throw vs throws

Last Updated : 5 Dec, 2025

Exception handling in Java provides mechanisms to handle runtime errors and maintain smooth program flow. Two commonly confused keywords in this mechanism are throw and throws, both used for handling exceptions but in completely different ways.

throw in Java

throw is used inside a method or block to explicitly throw an exception. You create an exception object and use throw to signal that an error has occurred.

  • Used to manually throw an exception.
  • Used inside a method.
  • Can throw only one exception at a time.
  • Must throw an object of Throwable type (Exception or Error).
Java
public class GFG {
    public static void main(String[] args)
    {
        // Use of unchecked Exception
        try {
            // double x=3/0;
            throw new ArithmeticException();
        }
        catch (ArithmeticException e) {
            e.printStackTrace();
        }
    }
}

Output:

java.lang.ArithmeticException
at GFG.main(GFG.java:7)

throws in Java

throws is used in the method declaration to indicate that a method may throw one or more checked exceptions. It tells the caller of the method to handle the exception.

  • Used in method signature.
  • Indicates possible exceptions a method can throw.
  • Can declare multiple exceptions.
  • Used mostly for checked exceptions (e.g., IOException).

Java throws

Java
import java.io.*;

public class ThrowsExample {

    static void readFile() throws IOException {
        FileReader fr = new FileReader("test.txt");
        System.out.println("File opened successfully");
    }

    public static void main(String[] args) {
        try {
            readFile();
        } catch (IOException e) {
            System.out.println("Exception Handled: " + e.getMessage());
        }
    }
}

Output:

Exception Handled: test.txt (No such file or directory)

throw vs throws

The main differences between throw and throws in Java are as follows:

throw

throws

It is used to explicitly throw an exception.

It is used to declare that a method might throw one or more exceptions.

It is used inside a method or a block of code.

It is used in the method signature.

It can throw both checked and unchecked exceptions.

It is only used for checked exceptions. Unchecked exceptions do not require throws

The method or block throws the exception.

The method's caller is responsible for handling the exception.

Stops the current flow of execution immediately.

It forces the caller to handle the declared exceptions.

throw new ArithmeticException("Error");

public void myMethod() throws IOException {}

Comment