In Java, as you may know, exceptions can be categorized into two: One that needs the throws clause or must be handled if you don't specify one and another one that doesn't. Now, see the following figure:

In Java, you can throw anything that extends the Throwable class. However, you don't need to specify a throws clause for all classes. Specifically, classes that are either an Error or RuntimeException or any of the subclasses of these two. In your case Exception is not a subclass of an Error or RuntimeException. So, it is a checked exception and must be specified in the throws clause, if you don't handle that particular exception. That is why you needed the throws clause.


From Java Tutorial:

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.

Now, as you know exceptions are classified into two: checked and unchecked. Why these classification?

Checked Exception: They are used to represent problems that can be recovered during the execution of the program. They usually are not the programmer's fault. For example, a file specified by user is not readable, or no network connection available, etc., In all these cases, our program doesn't need to exit, instead it can take actions like alerting the user, or go into a fallback mechanism(like offline working when network not available), etc.

Unchecked Exceptions: They again can be divided into two: Errors and RuntimeExceptions. One reason for them to be unchecked is that they are numerous in number, and required to handle all of them will clutter our program and reduce its clarity. The other reason is:

  • Runtime Exceptions: They usually happen due to a fault by the programmer. For example, if an ArithmeticException of division by zero occurs or an ArrayIndexOutOfBoundsException occurs, it is because we are not careful enough in our coding. They happen usually because some errors in our program logic. So, they must be cleared before our program enters into production mode. They are unchecked in the sense that, our program must fail when it occurs, so that we programmers can resolve it at the time of development and testing itself.

  • Errors: Errors are situations from which usually the program cannot recover. For example, if a StackOverflowError occurs, our program cannot do much, such as increase the size of program's function calling stack. Or if an OutOfMemoryError occurs, we cannot do much to increase the amount of RAM available to our program. In such cases, it is better to exit the program. That is why they are made unchecked.

For detailed information see:

  • Unchecked Exceptions — The Controversy
  • The Catch or Specify Requirement
Answer from Jomoos on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 11589302 › why-is-throws-exception-necessary-when-calling-a-function
java - Why is "throws Exception" necessary when calling a function? - Stack Overflow

In Java, as you may know, exceptions can be categorized into two: One that needs the throws clause or must be handled if you don't specify one and another one that doesn't. Now, see the following figure:

In Java, you can throw anything that extends the Throwable class. However, you don't need to specify a throws clause for all classes. Specifically, classes that are either an Error or RuntimeException or any of the subclasses of these two. In your case Exception is not a subclass of an Error or RuntimeException. So, it is a checked exception and must be specified in the throws clause, if you don't handle that particular exception. That is why you needed the throws clause.


From Java Tutorial:

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.

Now, as you know exceptions are classified into two: checked and unchecked. Why these classification?

Checked Exception: They are used to represent problems that can be recovered during the execution of the program. They usually are not the programmer's fault. For example, a file specified by user is not readable, or no network connection available, etc., In all these cases, our program doesn't need to exit, instead it can take actions like alerting the user, or go into a fallback mechanism(like offline working when network not available), etc.

Unchecked Exceptions: They again can be divided into two: Errors and RuntimeExceptions. One reason for them to be unchecked is that they are numerous in number, and required to handle all of them will clutter our program and reduce its clarity. The other reason is:

  • Runtime Exceptions: They usually happen due to a fault by the programmer. For example, if an ArithmeticException of division by zero occurs or an ArrayIndexOutOfBoundsException occurs, it is because we are not careful enough in our coding. They happen usually because some errors in our program logic. So, they must be cleared before our program enters into production mode. They are unchecked in the sense that, our program must fail when it occurs, so that we programmers can resolve it at the time of development and testing itself.

  • Errors: Errors are situations from which usually the program cannot recover. For example, if a StackOverflowError occurs, our program cannot do much, such as increase the size of program's function calling stack. Or if an OutOfMemoryError occurs, we cannot do much to increase the amount of RAM available to our program. In such cases, it is better to exit the program. That is why they are made unchecked.

For detailed information see:

  • Unchecked Exceptions — The Controversy
  • The Catch or Specify Requirement
Answer from Jomoos on stackoverflow.com
🌐
Reddit
reddit.com › r/learnprogramming › java throws and throw?
r/learnprogramming on Reddit: JAVA throws and throw?
Exceptions that are not a subclass of RuntimeException must be explicitly handled in Java. That way, you won't be surprised if someone forgets to put it in the comment or you forget to read the comment thoroughly. If your method calls a method that throws a particular exception, it's a compiler error unless you either catch the exception or declare that you throw that exception (which in turn forces any method that calls this method to deal with it).
🌐
GeeksforGeeks
geeksforgeeks.org › java › throw-throws-java
throw and throws in Java - GeeksforGeeks
06:58
In Java, exception handling is one of the effective means to handle runtime errors so that the regular flow of the application can be preserved. It handles runtime errors such as NullPointerException, ArrayIndexOutOfBoundsException, etc. To handle these errors effectively, Java provides two keywords, throw and throws.
Published: August 5, 2025
🌐
Stack Exchange
softwareengineering.stackexchange.com › questions › 263874 › why-shouldnt-a-method-throw-multiple-types-of-checked-exceptions
java - Why shouldn't a method throw multiple types of checked exceptions? - Software Engineering Stack Exchange

Lets consider the situation where you have the provided code of:

public void delete() throws IOException, SQLException {      // Non-Compliant
  /* ... */
}

The danger here is that the code that you write to call delete() will look like:

try {
  foo.delete()
} catch (Exception e) {
  /* ... */
}

This is bad too. And it will be caught with another rule that flags catching the base Exception class.

The key is to not write code that makes you want to write bad code elsewhere.

The rule that you are encountering is a rather common one. Checkstyle has it in its design rules:

ThrowsCount

Restricts throws statements to a specified count (1 by default).

Rationale: Exceptions form part of a method's interface. Declaring a method to throw too many differently rooted exceptions makes exception handling onerous and leads to poor programming practices such as writing code like catch(Exception ex). This check forces developers to put exceptions into a hierarchy such that in the simplest case, only one type of exception need be checked for by a caller but any subclasses can be caught specifically if necessary.

This precisely describes the problem and what the issue is and why you shouldn't do it. It is a well accepted standard that many static analysis tools will identify and flag.

And while you may do it according to language design, and there may be times when it is the right thing to do, it is something that you should see and immediately go "um, why am I doing this?" It may be acceptable for internal code where everyone is disciplined enough to never catch (Exception e) {}, but more often than not I've seen people cut corners especially in internal situations.

Don't make people using your class want to write bad code.


I should point out that the importance of this is lessened with Java SE 7 and later because a single catch statement can catch multiple exceptions (Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking from Oracle).

With Java 6 and before, you would have code that looked like:

public void delete() throws IOException, SQLException {
  /* ... */
}

and

try {
  foo.delete()
} catch (IOException ex) {
     logger.log(ex);
     throw ex;
} catch (SQLException ex) {
     logger.log(ex);
     throw ex;
}

or

try {
    foo.delete()
} catch (Exception ex) {
    logger.log(ex);
    throw ex;
}

Neither of these options with Java 6 are ideal. The first approach violates DRY. Multiple blocks doing the same thing, again and again - once for each exception. You want to log the exception and rethrow it? Ok. The same lines of code for each exception.

The second option is worse for several reasons. First, it means that you are catching all the exceptions. Null pointer gets caught there (and it shouldn't). Furthermore, you are rethrowing an Exception which means that the method signature would be deleteSomething() throws Exception which just makes a mess further up the stack as people using your code are now forced to catch(Exception e).

With Java 7, this isn't as important because you can instead do:

catch (IOException|SQLException ex) {
    logger.log(ex);
    throw ex;
}

Furthermore, the type checking if one does catch the types of the exceptions being thrown:

public void rethrowException(String exceptionName)
throws IOException, SQLException {
    try {
        foo.delete();
    } catch (Exception e) {
        throw e;
    }
}

The type checker will recognize that e may only be of types IOException or SQLException. I'm still not overly enthusiastic about the use of this style, but it isn't causing as bad code as it was under Java 6 (where it would force you to have the method signature be the superclass that the exceptions extend).

Despite all these changes, many static analysis tools (Sonar, PMD, Checkstyle) are still enforcing Java 6 style guides. It's not a bad thing. I tend to agree with a warning these to still be enforced, but you might change the priority on them to major or minor according to how your team prioritizes them.

If exceptions should be checked or unchecked... that is a matter of great debate that one can easily find countless blog posts taking up each side of the argument. However, if you are working with checked exceptions, you probably should avoid throwing multiple types, at least under Java 6.

Answer from user40980 on softwareengineering.stackexchange.com
🌐
Stack Exchange
softwareengineering.stackexchange.com › questions › 301967 › is-it-bad-practice-to-throw-multiple-custom-exceptions-in-java
Is it bad practice to throw multiple custom exceptions in Java? - Software Engineering Stack Exchange

Is it bad practice to throw multiple custom exceptions in Java?

No. It is good practice.

The only situation where multiple exceptions might be a (slightly) bad idea is if there is absolutely no possibility (ever!) of catching individual exceptions; i.e. the fine-grained exceptions won't serve any functional purpose. However, my opinion is that if you can make that assertion, then there is probably something wrong with the way that you / your team is using Java. And the counter-argument is that sensible use of multiple custom exceptions will help you to document the APIs ... even if you are never going to do more than catch-log-and-bail-out at runtime.

This is not to say that lots of custom exceptions will always be good:

  • If you go overboard and create a separate exception for everything, then you are probably adding unnecessary complexity. (In a lot of cases, different exception messages are sufficient.)

  • If you don't have a sensible inheritance hierarchy for your custom exceptions, then you may end up regretting it. (A well-designed hierarchy allows you to catch "classes" of exceptions, or declare methods as throwing them. It can make your code simpler.)

Answer from Stephen C on softwareengineering.stackexchange.com
🌐
Reddit
reddit.com › r/learnjava › is it good practice to always write "throws" in the method signature to show which exceptions could be raised? should this be done everytime?
r/learnjava on Reddit: Is it good practice to ALWAYS write "throws" in the method signature to show which exceptions could be raised? Should this be done everytime?
Disagree with everyone else here. Obviously, don't do it for unchecked exceptions just because those are straightforward. But some are saying "Fuck that just only throw unchecked exceptions." This is poor practice in my opinion. Modern, reliable code is fail-fast. Part of the fail-fast coding paradigm is having exceptions for possible failure modes of your methods and ensuring they are documented. Writing "Throws XYZException" at the end of a method signature is not that messy or difficult to read. It ensures you document it in-line if you're using Javadoc style documentation (you should), and it makes it crystal clear that the method being called can indeed throw that exception. You want your code to easily detect failures and very clearly lay out the cause of them. Exceptions are a necessity for this. Yes, they're ugly to handle sometimes, but the payoff of well-documenting all sources of error and easily tracing back where a failure occurred is worth it. Yes. Declare that it throws exceptions. Do not make using unchecked exceptions a habit to avoid dealing with writing the word "throws" at the end of your methods. Do not avoid exceptions altogether, they are your friend.
🌐
Stack Overflow
stackoverflow.com › questions › 6589489 › how-to-avoid-many-try-catch-blocks-in-java
exception - How to avoid many try catch blocks in java - Stack Overflow

If all you're doing is catching them and printing the stack trace regardless of the exception type, you can just wrap the code in one large try/catch block. To save many "catches", you can catch java.lang.Throwable which is the interface that all exceptions implement. If not, you can have a catch for every type of checked exception the code you're calling throws, and handle them specifically.

Eclipse keeps asking you to do so because Java code will not compile if the checked exceptions are not caught, or declared to be thrown by the caller.

+Adding this comment to the answer (Thanks, Paul Tomblin):

In production quality apps you'd be logging the trace, adding some logic where you're handling the exception in a right way, taking an alternate flow, and/or re-wrapping it in another exception and throwing it, etc. It all depends on the particular problem you're trying to solve.

Answer from lobster1234 on stackoverflow.com
🌐
Rollbar
rollbar.com › home › how to use the throws keyword in java (and when to use throw)
When and Why to Use Throw vs Throws in Java Exception Handling | Rollbar
September 16, 2024 - The throws keyword in Java is used to declare exceptions that can occur during the execution of a program. For any method that can throw exceptions, it is mandatory to use the throws keyword to list the exceptions that can be thrown.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › throwing.html
How to Throw Exceptions (The Java™ Tutorials > Essential Java Classes > Exceptions)
As you have probably noticed, the Java platform provides numerous exception classes. All the classes are descendants of the Throwable class, and all allow programs to differentiate among the various types of exceptions that can occur during the execution of a program. You can also create your own exception classes to represent problems that can occur within the classes you write. In fact, if you are a package developer, you might have to create your own set of exception classes to allow users to differentiate an error that can occur in your package from errors that occur in the Java platform or other packages.
🌐
Programiz
programiz.com › java-programming › throw-throws
Java throw and throws Keyword
Refer to Java Exceptions to learn in detail about checked and unchecked exceptions. Usually, we don't need to handle unchecked exceptions. It's because unchecked exceptions occur due to programming errors. And, it is a good practice to correct them instead of handling them. This tutorial will now focus on how to handle checked exceptions using throw and throws.
🌐
Unstop
unstop.com › home › blog › throws keyword in java | working, uses & more (+examples)
Throws Keyword In Java | Working, Uses & More (+Examples) // Unstop
November 27, 2024 - Avoid overloading the caller with too many exceptions if they are unrelated. For unrelated exceptions, consider dividing the method into smaller methods. ... Document the Exceptions: Always document the exceptions declared using throws in your method signature with Javadoc comments.
🌐
BeginnersBook -
beginnersbook.com › home › 2013 › april › difference between throw and throws in java
Difference between throw and throws in java
September 11, 2022 - Try to go through the separate articles of throw keyword and throws clause and then go through the differences, you will be able to understand better then. Thanks! ... By using Throw keyword in java you cannot throw more than one exception but using throws you can declare multiple exceptions.
🌐
Stack Overflow
stackoverflow.com › questions › 18491020 › what-does-throws-do-and-how-is-it-helpful
java - What does "Throws" do and how is it helpful? - Stack Overflow

You can manage an exception within a method using try and catch as you say. In that case, you do not need to use throws. For example:

public void myMethod()
{
  try {
    /* Code that might throw an exception */
  }
  catch (SpaceInvadersException exception) {
    /* Complicated error handling code */
  }
}

But suppose you had a thousand methods, all of which might throw a SpaceInvadersException. Then you would end up having to write all the complicated error handling code a thousand times. Of course, you could always create an ErrorHandler class with a dealWithSpaceInvadersException() method that you could call from them, but you'd still be stuck with a thousand try-catch blocks.

Instead, you tell the compiler that each of these thousand methods could throw a SpaceInvadersException. Then any method that calls one of these methods needs to deal with the error itself, either by using a try-catch, or by telling the compiler that it might throw a SpaceInvadersException. This is done using the throws keyword, like this:

public void myMethod() throws SpaceInvadersException
{
  /* Code that might throw an exception */
}

public void callingMethod()
{
  try {
    myMethod();
  }
  catch (SpaceInvadersException exception) {
    /* Complicated error handling code */
  }
}

In that case, you need to inform the compiler that myMethod could throw a SpaceInvadersException. This means that you can't call that method without dealing with the exception in some way (try-catch or using the throws keyword on the calling method). If throws weren't there, you could call the method without doing any exception handling, and get an exception that wasn't dealt with anywhere in the program (which would be bad).

Since it is always better to avoid code duplication, it is normally better to palm off your error handling to a try-catch in a much higher level function than it is to deal with it separately in all of the low level methods. That is why this mechanism exists.

Answer from John Gowers on stackoverflow.com
🌐
Medium
medium.com › @AlexanderObregon › java-exception-handling-throws-vs-try-catch-94b0abe1080d
Java Exception Handling — Throws vs. Try-Catch
March 17, 2024 - Here are some key practices to consider when handling exceptions in Java, aiming for clarity, efficiency, and maintainability in your code. When catching exceptions, specificity is key. Aim to catch the most specific exception types related to the operations you’re performing. This approach allows you to handle each exception in the most appropriate manner, providing clear and useful feedback for each distinct error condition. Catching overly broad exceptions, such as Exception or Throwable, can obscure the true nature of an error.
🌐
Prgrmmng
prgrmmng.com › home › series › java fundamentals › throw vs throws in java – key differences, syntax, and best practices
Throw vs Throws in Java – Key Differences, Syntax, and Best Practices | prgrmmng.com
July 30, 2025 - Frequent use of throw in loops can create performance overhead due to repeated object creation. Declaring too many exceptions in throws can make the API harder to use and maintain.
🌐
Stack Overflow
stackoverflow.com › questions › 4392446 › when-to-use-throws-in-a-java-method-declaration
exception - When to use throws in a Java method declaration? - Stack Overflow

If you are catching an exception type, you do not need to throw it, unless you are going to rethrow it. In the example you post, the developer should have done one or another, not both.

Typically, if you are not going to do anything with the exception, you should not catch it.

The most dangerous thing you can do is catch an exception and not do anything with it.

A good discussion of when it is appropriate to throw exceptions is here

When to throw an exception?

Answer from hvgotcodes on stackoverflow.com
🌐
Baeldung
baeldung.com › home › java › core java › difference between throw and throws in java
Difference Between Throw and Throws in Java | Baeldung
January 9, 2024 - We should always prefer the most specific exception. We need to find a class that fits the best for our exceptional event. For example, throw NumberFormatException instead of IllegalArgumentException. We should avoid throwing an unspecific Exception. For example, there is an Integer class in java.lang package.
🌐
Stack Exchange
softwareengineering.stackexchange.com › questions › 322770 › what-is-the-role-of-throws-exeption-in-method-definition-in-java
What is the role of "throws exeption" in method definition in Java? - Software Engineering Stack Exchange

What is the role of “throws exeption”

It's used for checked exceptions.

The idea is, if you write code to call a function that throws FoobarException, then the compiler will force you to either handle the exception, or to add the same throws FoobarException declaration to the function that you are writing.

It's a way to make sure that nobody will forget that a FoobarException might be thrown.

This stub doesn't attempt to return an int. Instead it throws exception right away. Yet, IDE accepts it as a valid syntax. The program compiles and runs.

Checked exceptions turn out not to be as popular as the language designers had hoped. In fact, they anticipated that when they created a whole category of unchecked exceptions.

UnsupportedOperationException is an unchecked exception. Unchecked exceptions work exactly the same as checked exceptions. The only difference is that you are not required to declare the exception when you write a method that could throw it. Every exception that inherits from java.lang.RuntimeException is unchecked.

The idea is, you're supposed to use checked exceptions for conditions that your program ought to handle in some graceful way (e.g., inform the user about a file-not-found instead of just crashing), and only use unchecked for exceptions that "can't possibly happen" unless your program is broken.

Is throw new UnsupportedOperationException considered a valid return for any return type?

No, it's not a "return", it's an exception. The compiler doesn't mind that your method never returns an int, because the compiler can tell that your method never returns at all.

Answer from Solomon Slow on softwareengineering.stackexchange.com
🌐
Medium
medium.com › javarevisited › throw-vs-throws-in-java-the-debate-that-never-ends-2281617c9aa9
🤔 Throw vs. Throws in Java: The Debate That Never Ends | by Rasathurai Karan | Javarevisited | Medium
March 18, 2025 - I still remember the first time I encountered throw and throws in Java. I had just started my journey as a software engineer, feeling proud after writing my first few hundred lines of code. Then, one…
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-throw-and-throws-in-java
Difference Between throw and throws in Java - GeeksforGeeks
July 11, 2025 - The throw and throws are the concepts of exception handling in Java where the throw keyword throws the exception explicitly from a method or a block of code, whereas the throws keyword is used in the signature of the method.