---
description: ‘throws’ keyword is used to declare that a method may throw one or some exceptions. The caller must catch the exceptions. Learn ‘throws’ keyword in Java with example.
title: Throws Keyword in Java
image: https://www.guru99.com/images/throws-keyword-in-java.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Throws Keyword in Java is used in a method declaration to announce the checked exceptions that the method may raise during execution. It delegates exception handling to the calling method instead of forcing a try-catch block inside.

- 📢 **Throws Defined:** Declares the exceptions a method may raise so callers can handle them.
- 🧱 **Syntax:** Placed after the method signature, e.g. method(args) throws Exception1, Exception2.
- 🔁 **Two Options:** Handle an exception with try-catch, or declare it with throws.
- ⚖️ **throw vs throws:** throw raises a single exception object; throws lists one or more in the signature.
- ⚠️ **Compiler Rule:** Checked exceptions must be either caught or declared, or compilation fails.

Read More

![Throws Keyword in Java](https://www.guru99.com/images/throws-keyword-in-java.png)

## Java Throws Keyword

The **Java throws keyword** is used to declare the exception information that may occur during the program execution. It gives information about the exception to the programmer. It is better to provide the exception handling code so that the normal flow of program execution can be maintained.

Java Throw Exception Syntax

Suppose in your java program you using a library method which throws an Exception

[  
![Java throws keyword]()](https://www.guru99.com/images/java/Java_throw.png)

In your program, you will handle this exception using try & catch.

```
import java.io.*;
class file1{
  public static void main(String[] args) {
     try{
           FileWriter file = new FileWriter("c:\\Data1.txt");
           file.write("Guru99");
           file.close();
    }
    catch(IOException){}
  }
}
```

If you do not handle the exception in a try catch block, compiling will fail. But almost every other method in the java library or even user defined may throw an exception or two. Handling all the exceptions using the try and catch block could be cumbersome and will hinder the coder’s throughput.

So java provides an option, wherein whenever you are using a risky piece of code in the method definition you declare it **throws** an exception without implementing try catch.

## Java Throw Exception Syntax

```
method (Arguments) throws Exception1,Exception2,Exception,… {}
```

## Throws Keyword in Java Example

Consider the same example as above with throws in the method declaration.

```
import java.io.*;
class file1{
    public static void main(String[] args) throws IOException{
      FileWriter file = new FileWriter("c:\\Data1.txt");
      file.write("Guru99");
      file.close();
    }
}
```

Note: To successfully the above codes, first create an empty text file with name Data1.txt in your C drive. In sum, there are two methods to handle Exceptions:

1. Put the Exception causing code in try and catch block.
2. Declare the method to be throwing an Exception

If either of the above two is not done, the [compiler](https://www.guru99.com/compiler-design-tutorial.html) gives an error. The idea behind enforcing this rule is that you as a programmer are aware that a certain piece of code could be risky and may throw an exception.

**Don't Miss:**

- [What is Abstraction in Java? (with Example)](https://www.guru99.com/java-data-abstraction.html)
- [Constructor Overloading in Java](https://www.guru99.com/constructor-overloading-in-java.html)
- [Armstrong Number in JAVA Program Using For Loop](https://www.guru99.com/java-program-check-armstrong-number.html)
- [JDK vs JRE vs JVM in Java – Difference Between Them](https://www.guru99.com/difference-between-jdk-jre-jvm.html)

### What is the difference between throw and throws?

| throw | throws |
| --- | --- |
| It is used to create a new Exception object and throw it | It is used in method definition, to declare that a risky method is being called. |
| Using throw keyword you can declare only one Exception at a time | Using throws keyword you can declare multiple exception at a time. |
| **Example:** throw new IOException(“can not open connection”); | **Example:** throws IOException, ArrayIndexBoundException; |

## FAQs

⚖️ What is the difference between throw and throws in Java?

The throw keyword raises a single exception object inside a method body, while the throws keyword appears in the method signature to declare one or more exceptions the method may pass to its caller.

➕ Can a method declare multiple exceptions with throws?

Yes. A single throws clause can list several exceptions separated by commas, for example throws IOException, SQLException. The calling method must then handle or further declare each of them.

🔓 Do you need throws for unchecked exceptions?

No. Unchecked exceptions (subclasses of RuntimeException) do not need to be declared with throws. The compiler only enforces declaration or handling for checked exceptions such as IOException.

🤖 How can AI help handle Java exceptions?

AI can suggest appropriate try-catch blocks, recommend whether to catch or declare an exception, generate meaningful error messages, and detect swallowed exceptions, helping developers write safer and more maintainable error-handling code.

🧠 Can AI suggest which exceptions a method should declare?

Yes. AI can analyze a method body, identify risky operations such as file or network access, and recommend the checked exceptions to declare in the throws clause, reducing missed declarations and compile errors.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/throws-keyword-in-java.png","url":"https://www.guru99.com/images/throws-keyword-in-java.png","width":"700","height":"250","caption":"Throws Keyword in Java","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/throws-keyword-in-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/java-tutorials","name":"Java Tutorials"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/throws-keyword-in-java.html","name":"Throws Keyword in Java"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/throws-keyword-in-java.html#webpage","url":"https://www.guru99.com/throws-keyword-in-java.html","name":"Throws Keyword in Java","dateModified":"2026-10-01T12:35:50+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/throws-keyword-in-java.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/throws-keyword-in-java.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Java Tutorials","headline":"Throws Keyword in Java","description":"\u2018throws\u2019 keyword is used to declare that a method may throw one or some exceptions. The caller must catch the exceptions. Learn \u2018throws\u2019 keyword in Java with example.","keywords":"java","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-01T12:35:50+05:30","image":{"@id":"https://www.guru99.com/images/throws-keyword-in-java.png"},"copyrightYear":"2026","name":"Throws Keyword in Java","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between throw and throws in Java?","acceptedAnswer":{"@type":"Answer","text":"The throw keyword raises a single exception object inside a method body, while the throws keyword appears in the method signature to declare one or more exceptions the method may pass to its caller."}},{"@type":"Question","name":"Can a method declare multiple exceptions with throws?","acceptedAnswer":{"@type":"Answer","text":"Yes. A single throws clause can list several exceptions separated by commas, for example throws IOException, SQLException. The calling method must then handle or further declare each of them."}},{"@type":"Question","name":"Do you need throws for unchecked exceptions?","acceptedAnswer":{"@type":"Answer","text":"No. Unchecked exceptions (subclasses of RuntimeException) do not need to be declared with throws. The compiler only enforces declaration or handling for checked exceptions such as IOException."}},{"@type":"Question","name":"How can AI help handle Java exceptions?","acceptedAnswer":{"@type":"Answer","text":"AI can suggest appropriate try-catch blocks, recommend whether to catch or declare an exception, generate meaningful error messages, and detect swallowed exceptions, helping developers write safer and more maintainable error-handling code."}},{"@type":"Question","name":"Can AI suggest which exceptions a method should declare?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI can analyze a method body, identify risky operations such as file or network access, and recommend the checked exceptions to declare in the throws clause, reducing missed declarations and compile errors."}}]}],"@id":"https://www.guru99.com/throws-keyword-in-java.html#schema-1126928","isPartOf":{"@id":"https://www.guru99.com/throws-keyword-in-java.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/throws-keyword-in-java.html#webpage"}}]}
```
