Your current method covers the first point - to take an exception as parameter.
The throws Exception is unnecessary if you dont throw it from a method, but it is needed to cover the second point.

As commenters pointed, you just need to use the throw keyword to throw an exception, so the method could look like:

public void throwException (Exception ex) throws Exception {
    //some other code maybe?
    throw ex;
}

This implementation has a little flaw. When the null is passed as a parameter to it, the method will throw a NullPointerException, because the throw keyword accepts objects of the Throwable class or its subclasses (Exception is a subclass of Throwable).
To avoid NullPointerException (which is an unchecked-exception), simple if statement can be used:

public void throwException (Exception ex) throws Exception {
    if (ex != null) {
        throw ex;
    }
    //just for presentation,below it throws new Exception
    throw new Exception("ex parameter was null");
}

Edit:
As @Slaw suggested, in that very small case adding the null-check and throwing new Exception just disguises the NullPointerException. Without the null-check and throw new... the NPE will be thrown from that method and its stacktrace will show exact line of throw ex when the null is passed to that method.
The NPE is a subtype of RuntimeException class and the subtypes of RuntimeException doesn't need to be explicitly declared in method signature when they are thrown from that method. Like here:

public static void throwNPE(Exception e) {
    throw new NullPointerException();
}

The RuntimeException and its subclasses are called an unchecked-exceptions. Other classes extending one of Exception or Throwable classes are call checked-exceptions, because if a method throws them, it must declare that exception (or superclass) in the signature or explicitly try-catch it.

The proper use of null-check would be when the method would throw a more specific kind of exception (like IOException or a new subclass of Exception/Throwable) and the when the other method using the one which throws that new type of Exception would try-catch that specific type the NPE wouldn't be caught.

Just for good practices, when dealing with try-catch it's much better to catch exact types of thrown Exceptions instead of general Exception/Throwable. It helps to understand the real cause of exception, debug and fix code.

Answer from itwasntme on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › throw-throws-java
throw and throws in Java - GeeksforGeeks
Java provides specific keywords to handle and manage exceptions effectively. ... The throw keyword in Java is used to explicitly throw an exception from a method or any block of code.
Published   May 28, 2026
🌐
W3Schools
w3schools.com › java › ref_keyword_throws.asp
Java throws Keyword
The throws keyword indicates what exception type may be thrown by a method. There are many exception types available in Java: ArithmeticException, ClassNotFoundException, ArrayIndexOutOfBoundsException, SecurityException, etc.
Discussions

How to throw a checked exception from a java thread? - Stack Overflow
Hey, I'm writing a network application, in which I read packets of some custom binary format. And I'm starting a background thread to wait for incoming data. The problem is, that the compiler doesn... More on stackoverflow.com
🌐 stackoverflow.com
Explicitly throwing the exception in java in method calls - Stack Overflow
I have the below method in which the last parameter I want to throw the exception with my custom error message , I am doing it by the following way as shown below.. String errorMessage = More on stackoverflow.com
🌐 stackoverflow.com
java - Why is "throws Exception" necessary when calling a function? - Stack Overflow
Similarly, if Method3 is not handling the exception in its body then, it had to define throws Exception in its method definition to give heads up its calling method. extension of the previous comment ... In Java, as you may know, exceptions can be categorized into two: One that needs the throws ... More on stackoverflow.com
🌐 stackoverflow.com
When to throw an exception? When to try and catch and exception.
Right, the way I understood try {} and catch {} as an absolute beginner was. Every time you write code and you are working with some sort of information. For example, lets say make a simple application that asks the user to enter a number (integer) and then you print out the number they have entered. The problem is if they enter a string when you are only accepting integers as your datatype. you now need to catch that problem so it doesn't crash the application. Example: public static void main(String[] args) { Scanner get_input = new Scanner(System.in) ; //With this line we create a new object called "get_input". System.out.print("Please enter a number: ") ; // We ask the user to enter a number int theNumber = get_input.nextInt(); // We read the number the user enters and we store it a variable. System.out.print("Your number was " + theNumber); // we print out their number. } This would all work fine but if they entered a word like "hello" instead of a number like 12 the program would crash. that's why we use the keyword try. try{ // the code here int theNumber = get_input.nextInt(); // We read the number the user enters and we store it a variable. }catch(Exception e) // if something goes wrong in the "try" block above we take the error message and we store it in the variable e { System.out.print("Please enter a valid number."); } here is also a video tutorial https://youtu.be/K_-3OLkXkzY More on reddit.com
🌐 r/javahelp
19
10
June 9, 2018
Top answer
1 of 1
3

Your current method covers the first point - to take an exception as parameter.
The throws Exception is unnecessary if you dont throw it from a method, but it is needed to cover the second point.

As commenters pointed, you just need to use the throw keyword to throw an exception, so the method could look like:

public void throwException (Exception ex) throws Exception {
    //some other code maybe?
    throw ex;
}

This implementation has a little flaw. When the null is passed as a parameter to it, the method will throw a NullPointerException, because the throw keyword accepts objects of the Throwable class or its subclasses (Exception is a subclass of Throwable).
To avoid NullPointerException (which is an unchecked-exception), simple if statement can be used:

public void throwException (Exception ex) throws Exception {
    if (ex != null) {
        throw ex;
    }
    //just for presentation,below it throws new Exception
    throw new Exception("ex parameter was null");
}

Edit:
As @Slaw suggested, in that very small case adding the null-check and throwing new Exception just disguises the NullPointerException. Without the null-check and throw new... the NPE will be thrown from that method and its stacktrace will show exact line of throw ex when the null is passed to that method.
The NPE is a subtype of RuntimeException class and the subtypes of RuntimeException doesn't need to be explicitly declared in method signature when they are thrown from that method. Like here:

public static void throwNPE(Exception e) {
    throw new NullPointerException();
}

The RuntimeException and its subclasses are called an unchecked-exceptions. Other classes extending one of Exception or Throwable classes are call checked-exceptions, because if a method throws them, it must declare that exception (or superclass) in the signature or explicitly try-catch it.

The proper use of null-check would be when the method would throw a more specific kind of exception (like IOException or a new subclass of Exception/Throwable) and the when the other method using the one which throws that new type of Exception would try-catch that specific type the NPE wouldn't be caught.

Just for good practices, when dealing with try-catch it's much better to catch exact types of thrown Exceptions instead of general Exception/Throwable. It helps to understand the real cause of exception, debug and fix code.

🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › throwing.html
How to Throw Exceptions (The Java™ Tutorials > Essential Java Classes > Exceptions)
The pop method checks to see whether any elements are on the stack. If the stack is empty (its size is equal to 0), pop instantiates a new EmptyStackException object (a member of java.util) and throws it. The Creating Exception Classes section in this chapter explains how to create your own exception classes.
🌐
JetBrains
blog.jetbrains.com › home › intellij idea › easy hacks: how to throw java exceptions
Easy Hacks: How to Throw Java Exceptions - The JetBrains Blog
March 12, 2024 - Note that this is also true for exceptions that may occur in third-party code, such as java.nio. In the following screenshot, you’ll see the readString method may throw an IOException, and IntelliJ IDEA again suggests either adding the exception to the method signature (throws IOException) or handling the exception using a try/catch block.
🌐
Rollbar
rollbar.com › home › how to throw exceptions in java
How to Throw Exceptions in Java | Rollbar
November 29, 2025 - The detailMessage parameter gives the details of the message for this exception, and the throwable parameter gives the cause of this exception. The key takeaway: every exception needs a message explaining what went wrong, and optionally a cause pointing to the underlying exception that triggered it. Java’s built-in exceptions don’t always provide the information we need.
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › java-exception-handling-throws-vs-try-catch-94b0abe1080d
Java Exception Handling — Throws vs. Try-Catch
March 17, 2024 - Exceptions are events that disrupt ... to handle exceptions are by using the try-catch blocks and declaring exceptions in method signatures with the throws keyword....
🌐
DataCamp
datacamp.com › doc › java › throw
throw Keyword in Java: Usage & Examples
The throw keyword in Java is used to explicitly throw an exception from a method or any block of code.
🌐
W3Schools
w3schools.com › java › java_try_catch.asp
Java Exceptions (Try...Catch)
As mentioned in the Errors chapter, ... such as coding mistakes, invalid input, or unexpected situations. When an error occurs, Java will normally stop and generate an error message. The technical term for this is: Java will throw an exception (throw an error)....
Top answer
1 of 10
50

To be able to send the exception to the parent thread, you can put your background thread in a Callable (it allows throwing also checked exceptions) which you then pass to the submit method of some Executor. The submit method will return a Future which you can then use to get the exception (its get method will throw an ExecutionException which contains the original exception).

2 of 10
44

Caveat: this may not meet your needs if you have to use the exception mechanism.

If I understand you correctly, you don't actually need the exception to be checked (you've accepted the answer suggesting an unchecked exception) so would a simple listener pattern be more appropriate?

The listener could live in the parent thread, and when you've caught the checked exception in the child thread, you could simply notify the listener.

This means that you have a way of exposing that this will happen (through public methods), and will be able to pass more information than an exception will allow. But it does mean there will be a coupling (albeit a loose one) between the parent and the child thread. It would depend in your specific situation whether this would have a benefit over wrapping the checked exception with an unchecked one.

Here's a simple example (some code borrowed from another answer):

public class ThingRunnable implements Runnable {
    private SomeListenerType listener;
    // assign listener somewhere

    public void run() {
        try {
            while(iHaveMorePackets()) { 
                doStuffWithPacket();
            }
        } catch(Exception e) {
            listener.notifyThatDarnedExceptionHappened(...);
        }
    }
 }

The coupling comes from an object in the parent thread having to be of type SomeListenerType.

🌐
Quora
quora.com › In-Java-when-you-use-a-Throw-Exception-are-you-skipping-over-bad-code-to-allow-the-program-to-continue-running-or-when-would-it-be-used-for
In Java, when you use a Throw Exception, are you skipping over bad code to allow the program to continue running or when would it be used for? - Quora
Answer (1 of 3): Here’s an excellent writeup on the use and misuse of exceptions: Vexing exceptions Personally, I tend to catch exception in one of two places: immediate outside the function that throws it (these would be the ‘vexing’ exceptions from the above article), or at the very ...
Top answer
1 of 9
192

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
2 of 9
35

Java requires that you handle or declare all exceptions. If you are not handling an Exception using a try/catch block then it must be declared in the method's signature.

For example:

class throwseg1 {
    void show() throws Exception {
        throw new Exception();
    }
}

Should be written as:

class throwseg1 {
    void show() {
        try {
            throw new Exception();
        } catch(Exception e) {
            // code to handle the exception
        }
    }
}

This way you can get rid of the "throws Exception" declaration in the method declaration.

🌐
Baeldung
baeldung.com › home › java › core java › throwing exceptions in constructors
Throwing Exceptions in Constructors | Baeldung
January 8, 2024 - Here, we’re throwing InstantiationException, which is a checked exception. Even though throwing any type of exception is allowed, let’s establish some best practices. First, we don’t want to throw “java.lang.Exception”. This is because the caller cannot possibly identify what kind ...
🌐
Baeldung
baeldung.com › home › java › core java › exception handling in java
Exception Handling in Java | Baeldung
December 17, 2025 - Now, there are times when we have code that needs to execute regardless of whether an exception occurs, and this is where the finally keyword comes in. In our examples so far, there ‘s been a nasty bug lurking in the shadows, which is that Java by default won’t return file handles to the operating system. Certainly, whether we can read the file or not, we want to make sure that we do the appropriate cleanup! ... public int getPlayerScore(String playerFile) throws FileNotFoundException { Scanner contents = null; try { contents = new Scanner(new File(playerFile)); return Integer.parseInt(contents.nextLine()); } finally { if (contents != null) { contents.close(); } } }
🌐
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 - In Java, every subclass of Error and RuntimeException is an unchecked exception. A checked exception is everything else under the Throwable class.
🌐
Reddit
reddit.com › r/javahelp › when to throw an exception? when to try and catch and exception.
r/javahelp on Reddit: When to throw an exception? When to try and catch and exception.
June 9, 2018 -

Hello, I am lookign for a clear example of when you throw an exception and how to use it do you catch that thrown exception somewhere or does it end there. When do you use try and catch block for exceptions? I understand the concept of exceptions but that part isn't very clear to me. One method throws it other method catches it and so on.

Top answer
1 of 4
6
Right, the way I understood try {} and catch {} as an absolute beginner was. Every time you write code and you are working with some sort of information. For example, lets say make a simple application that asks the user to enter a number (integer) and then you print out the number they have entered. The problem is if they enter a string when you are only accepting integers as your datatype. you now need to catch that problem so it doesn't crash the application. Example: public static void main(String[] args) { Scanner get_input = new Scanner(System.in) ; //With this line we create a new object called "get_input". System.out.print("Please enter a number: ") ; // We ask the user to enter a number int theNumber = get_input.nextInt(); // We read the number the user enters and we store it a variable. System.out.print("Your number was " + theNumber); // we print out their number. } This would all work fine but if they entered a word like "hello" instead of a number like 12 the program would crash. that's why we use the keyword try. try{ // the code here int theNumber = get_input.nextInt(); // We read the number the user enters and we store it a variable. }catch(Exception e) // if something goes wrong in the "try" block above we take the error message and we store it in the variable e { System.out.print("Please enter a valid number."); } here is also a video tutorial https://youtu.be/K_-3OLkXkzY
2 of 4
2
I see a lot words in the comments. The way I see it is pretty simple. If the error is fatal / unrecoverable or if you're building an API and expect the user to catch the errors, you throw it. If you can correct the error in your UI then you should catch it, ex. your app opens files but the file specified can't be found, catch the error and bring up a UI prompt for the user to select a new file.
🌐
BeginnersBook
beginnersbook.com › 2013 › 04 › throw-in-java
How to throw exception in java with example
September 11, 2022 - For example, we can throw ArithmeticException when we divide number by 5, or any other numbers, what we need to do is just set the condition and throw any exception using throw keyword. Throw keyword can also be used for throwing custom exceptions, I have covered that in a separate tutorial, ...
🌐
CodeGym
codegym.cc › java blog › java exceptions › java throw exception
Java throw Exception
May 2, 2023 - If so, it means that an exception is being thrown in the method. This can propagate exceptions up the call stack and indicate that exceptions do not need to be handled in the current method. In Java, "throws" can also be used to refer to custom exceptions defined in a program.
🌐
FavTutor
favtutor.com › blogs › java-throw-exception
How to Throw an Exception in Java (with Examples)
December 26, 2022 - The syntax for using the throw keyword to throw exceptions is: ... Here, the exception i.e, Instance must be of type Throwable or a subclass of Throwable.