Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Difference Between throw and throws in Java

    The throw and throws are the two keywords used in exception handling. In this article, you will learn about how both of them are different from one another.

    Difference Between throw and throws in Java

    Throw Throws
    This keyword is used for explicitly throwing an exception. This keyword is used for declaring any exception.
    Programmers cannot disseminate checked exceptions using the throw keyword. Programmers can disseminate checked exceptions using throws keyword.
    An instance trails the throw keyword. A class trails the throws keyword.
    You have to use the throw keyword inside any method. You have to use the throws keyword with any sign of the method.
    Many exceptions cannot be thrown. Many exceptions can be declared using the throws.
    Code Snippet:
    Class Example
    {
    public static void main(String argu[])
    {
    throw new ArithmeticException("Divided by zero");
    }
    }
    Code Snippet:
    public void testExc() throws SQLException , IOException


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.