• The try block will execute a sensitive code which can throw exceptions
  • The catch block will be used whenever an exception (of the type caught) is thrown in the try block
  • The finally block is called in every case after the try/catch blocks. Even if the exception isn't caught or if your previous blocks break the execution flow.
  • The throw keyword will allow you to throw an exception (which will break the execution flow and can be caught in a catch block).
  • The throws keyword in the method prototype is used to specify that your method might throw exceptions of the specified type. It's useful when you have checked exception (exception that you have to handle) that you don't want to catch in your current method.

Resources :

  • oracle.com - Lesson: Exceptions

On another note, you should really accept some answers. If anyone encounter the same problems as you and find your questions, he/she will be happy to directly see the right answer to the question.

Answer from Colin Hebert on Stack Overflow
Top answer
1 of 8
99
  • The try block will execute a sensitive code which can throw exceptions
  • The catch block will be used whenever an exception (of the type caught) is thrown in the try block
  • The finally block is called in every case after the try/catch blocks. Even if the exception isn't caught or if your previous blocks break the execution flow.
  • The throw keyword will allow you to throw an exception (which will break the execution flow and can be caught in a catch block).
  • The throws keyword in the method prototype is used to specify that your method might throw exceptions of the specified type. It's useful when you have checked exception (exception that you have to handle) that you don't want to catch in your current method.

Resources :

  • oracle.com - Lesson: Exceptions

On another note, you should really accept some answers. If anyone encounter the same problems as you and find your questions, he/she will be happy to directly see the right answer to the question.

2 of 8
41

If you execute the following example, you will know the difference between a Throw and a Catch block.

In general terms:

The catch block will handle the Exception

throws will pass the error to his caller.

In the following example, the error occurs in the throwsMethod() but it is handled in the catchMethod().

public class CatchThrow {

private static void throwsMethod() throws NumberFormatException {
    String  intNumber = "5A";

    Integer.parseInt(intNumber);
}

private static void catchMethod() {
    try {

        throwsMethod();

    } catch (NumberFormatException e) {
        System.out.println("Convertion Error");
    }

}

public static void main(String[] args) {
    // TODO Auto-generated method stub

    catchMethod();
}

}
๐ŸŒ
Quora
quora.com โ€บ What-is-the-main-difference-between-throws-and-try-catch-in-Java
What is the main difference between throws and try-catch in Java? - Quora
Answer (1 of 3): For me, exception handling is more like answering the question: Who is responsible for potential error/exception? Example: Mike needs to buy a champagne for his birthday party. However, he is so busy with other stuff that he asks his friend, Joey, to get it on his way. Joey sa...
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-exception-handling-throws-vs-try-catch-94b0abe1080d
Java Exception Handling โ€” Throws vs. Try-Catch
March 17, 2024 - Avoid Overusing Rethrown Exceptions: While rethrowing exceptions with additional context or as a different type can be useful, doing so excessively can complicate the error handling logic and make the flow harder to follow. Document Rethrown Exceptions: Clearly document any exceptions that your method rethrows, especially if they change the type or add context. This documentation is important for other developers who use your method. Combining throws and try-catch offers Java developers a nuanced approach to exception handling.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ try/catch vs throws?
r/learnprogramming on Reddit: Try/Catch vs Throws?
December 9, 2015 -

Pretty new student to CS here. I'm curious what the point of throwing an exception is. Does it actually do anything?

Wouldn't the try/catch always be better as you catch for errors and actually deal with them in some way?

Top answer
1 of 5
8
The try/catch block catches exceptions that are thrown, so they pretty much do opposite things. The throw exception says "Hey, here's an exception" and the try/catch block decides what to do with it (which can include printing an error message, throwing the exception again, throwing a slightly different exception, or handling the exception and continuing normally).
2 of 5
7
I'm curious what the point of throwing an exception is. The point is to signal that an exceptional situation has occurredโ€Šโ€”โ€Ša connection could not be made, a file does not exist, the specified key does not exist, the given index is out of bounds, etc. Does it actually do anything? Would would be the point if it didn't do anything? What happens when you throw an exception is out of your hands. It depends on all the stack frames above you, i.e. the person that called you, their caller, and their caller, and so on. Wouldn't the try/catch always be better as you catch for errors and actually deal with them in some way? I don't know what this means. throw is not an alternative to try and catch. The three are all related. Something has to be thrown (either by you, or code that you call) in order to have something to catch. If you can handle a specific kind of exception, then you should catch it and handle it. If you can't, you should either let the exception propagate upwards (i.e. do nothing), or you should catch and rethrow if the exception type needs to be translated into something that can be handled by somebody up the ladder from you.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ try-catch-throw-and-throws-in-java
Try, catch, throw and throws in Java
In this tutorial, we will learn about the try-catch, throw, and throws keywords in Java. The try-catch block is used for handling exceptions. If you have a doubt on a piece of code that it may throw an exception, you can put that code in a try block. If an exception occurs, the catch block ...
๐ŸŒ
Benchresources
benchresources.net โ€บ home โ€บ java โ€บ java โ€“ difference between throws-clause and try-catch-finally blocks ?
Java - Difference between throws-clause and try-catch-finally blocks ? - BenchResources.Net
July 8, 2022 - throw is used to throw exception from executing block; it could be try-block or catch-block (from inside a method) throws is used to indicate that particular method is possibly throws these exceptions; again method can throws any number of exceptions ยท As explained above, throws clause is used to indicate that particular exception is possibly thrown from executing method at run-time ยท Whereas try-catch block is used to handle exception scenario...
Find elsewhere
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2013 โ€บ 04 โ€บ difference-between-throw-and-throws-in-java
Difference between throw and throws in java
Actually the usage of throw and throws is completely different. It depends whether you are throwing an exception or handling it. To throw an exception we use throw keyword while to handle (catch) an exception we use throws clause.
๐ŸŒ
Preplaced
preplaced.in โ€บ blog โ€บ throws-vs-try-catch-5
Throws Vs Try-Catch With Examples in Java-Selenium
๐Ÿ‘‰ When to Use:Use try-catch when you want to handle exceptions immediately within a particular code block. ๐Ÿ‘‰ Pros:Provides a localized way to handle exceptions, making the code more robust.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 22713 โ€บ whats-the-difference-between-throws-exception-and-try-catch
whats the difference between throws exception and try catch | Sololearn: Learn to code for FREE!
In simple Way try is used for RISKY ... try block and if there is any Exception occurs like (Division /O) then it will Throw that exception to CATCH block and Catch is use to varify exception type and Handle It....
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ java โ€บ try, catch, finally and throw in java with examples
Try, Catch, Finally And Throw In Java With Examples
April 1, 2025 - The finally block generally follows the try or try-catch block. We use the throws keyword to declare exceptions with the method signature and throw is used explicitly to throw exceptions. We usually use throw keyword to throw custom exceptions.
Top answer
1 of 3
3

Why not to try in code?

public class ExPerformanceTest {

    private int someVar = 0;
    private int iterations = 100000000;

    @Test
    public void throwTest() throws Exception {
        long t;
        t = System.currentTimeMillis();
        for (int i = 0; i < iterations; i++) {
            throwingMethod();
        }
        t = System.currentTimeMillis() - t;
        System.out.println("Throw Test took " + t + " ms");
    }

    @Test
    public void tryCatchTest() throws Exception {
        long t;
        t = System.currentTimeMillis();
        for (int i = 0; i < iterations; i++) {
            tryCatchMethod();
        }
        t = System.currentTimeMillis() - t;
        System.out.println("Try-Catch Test took " + t + " ms");
    }

    @Test
    public void anotherTryCatchTest() throws Exception {
        long t;
        t = System.currentTimeMillis();
        for (int i = 0; i < iterations; i++) {
            tryCatchMethodThatNeverEverThrows();
        }
        t = System.currentTimeMillis() - t;
        System.out.println("Try-Catch That Never Throws Test took " + t + " ms");
    }

    private void throwingMethod() throws Exception {
        // do some stuff here
        someVar++;
        willNeverThrow();
    }

    private void tryCatchMethod() {
        try {
            // do some stuff here
            someVar++;
            willNeverThrow();
        } catch (Exception e) {
            System.out.println("You shouldn't see this ever");
        }
    }

    private void tryCatchMethodThatNeverEverThrows() {
        try {
            // do some stuff here
            someVar++;
        } catch (Exception e) {
            System.out.println("You shouldn't see this ever");
        }
    }

    private void willNeverThrow() throws Exception {
        if (someVar == -1) {
            throw new RuntimeException("Shouldn't happen");
        }
    }
}

That gives quite expected numbers:

Run 1

Try-Catch That Never Throws Test took 36 ms
Throw Test took 139 ms
Try-Catch Test took 160 ms

Run 2

Try-Catch That Never Throws Test took 26 ms
Throw Test took 109 ms
Try-Catch Test took 113 ms

Run 3

Try-Catch That Never Throws Test took 32 ms
Throw Test took 137 ms
Try-Catch Test took 194 ms

Obviously, JVM spotted that tryCatchMethodThatNeverEverThrows doesn't effectively need a catch part and optimized that, so the method execution took few times less, than others.

In other case, having a catch clause with handling takes some time indeed.

2 of 3
0

From the paper, Optimizing Java Programs in the Presence of Exceptions:

The Java language specification requires that exceptions be precise, which implies that:

  1. when an exception is thrown, the program state observable at the entry of the corresponding exception handler must be the same as in the original program; and
  2. exception(s) must be thrown in the same order as specified by the original (unoptimized) program.

To satisfy the precise exception requirement, Java compilers disable many important optimizations across instructions that may throw an exception...This hampers a wide range of program optimizations such as instruction scheduling, instruction selection, loop transformations, and parallelization.

In presence of a try-catch block, JVM maintains an exception table. For each new catch block, the compiler will add an entry to the exception table. If an exception occurs, JVM needs to go through each entry in the table and check if the exception is defined in the exception table (this requires type analysis too). The result is a much more complex control structure which in turn will greatly hamper compiler optimization.

throws on the other hand, allows the exception to propagate. Although this might be better for performance, an uncaught exception can potentially crash the thread, the whole application, or even kill the JVM itself!

How to decide when to use try-catch?

I think correctness and reliability concerns play a more important role than performance here. But if you have only performance in mind, the authors in this link have done extensive bench-marking for java code in presence of exceptions. Their most basic conclusion is that if you use exceptions for truly exceptional cases (not as a means for program flow control) there will not be much of a performance hit.

๐ŸŒ
Medium
medium.com โ€บ @arunkumarsambu โ€บ try-catch-vs-throws-in-java-1728f2f891eb
Try-Catch Vs Throws in Java
September 6, 2024 - In Java, throws and try-catch blocks are used to handle exception, but they server different puposes and used in different contexts.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-using-try-catch-blocks-inside-the-method-instead-of-using-throws-exceptions-in-the-method-declaration-in-JAVA
What is the difference between using try-catch blocks inside the method instead of using throws exceptions in the method declaration in JAVA? - Quora
Answer (1 of 14): It's part of the method's signature or โ€œcontractโ€. Either the exception can be handled within the method call context, or it can't. In which case the caller should provide a way of dealing with the exception. Sometimes all you can do is log and exit.
๐ŸŒ
Quora
quora.com โ€บ When-do-I-use-try-catch-and-when-do-I-use-throw-throws
When do I use try/catch and when do I use throw/throws? - Quora
Answer (1 of 3): Try and catch: When u want to to catch a exception in a particular lines of codes then we use try and catch like: public void goThis(){ try{ string str = downloadString(); System.out.println(str); } catch(NullPointerExceptio e){ S...
๐ŸŒ
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 - Throws keyword can be placed in the method declaration. It denotes which exceptions can be thrown from this method. We must handle these exceptions with try-catch.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ try-catch-throw-and-throws-in-java
Java Try Catch Block | GeeksforGeeks
January 2, 2025 - The scanner class can handle input from different places, like as we are typing at the console, reading from a file, or working with data streams. This class was introduced in Java 5. Before ... The Java if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e. if a certain condition is true then a block of statements is executed otherwise not.Example:Java// Java program to illustrate If st
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ throw-throws-java
throw and throws in Java - GeeksforGeeks
The flow of execution of the program stops immediately after the throw statement is executed and the nearest enclosing try block is checked to see if it has a catch statement that matches the type of exception. If it finds a match, controlled is transferred to that statement otherwise next enclosing try block is checked and so on.
Published ย  August 5, 2025
๐ŸŒ
Medium
medium.com โ€บ @sidharth.shukla19 โ€บ throws-vs-try-catch-with-examples-in-java-selenium-e7f565804a94
Throws Vs Try-Catch With Examples in Java-Selenium | by Sidharth Shukla | Medium
December 6, 2023 - While conducting interviews, Iโ€™ve ... ... In Java, try-catch blocks are used for exception handling, while throws is used in method declarations to indicate that a method might throw a specific type of exception....