1.

What Is Throws Clause?

Answer»

If in a method we don't want to HANDLE any exception but want to leave it to the CALLING method to handle any exception that is thrown by the called method, it is done using throws keyword.

Using throws a method can just declare the exception it may throw and callers of the method have to provide exception handling for those EXCEPTIONS (or they can ALSO declare them using throws).

General form of a method declaration that INCLUDES a throws clause

type method-name(parameter-list) throws exception-list

{
// body of method
}

If in a method we don't want to handle any exception but want to leave it to the calling method to handle any exception that is thrown by the called method, it is done using throws keyword.

Using throws a method can just declare the exception it may throw and callers of the method have to provide exception handling for those exceptions (or they can also declare them using throws).

General form of a method declaration that includes a throws clause

type method-name(parameter-list) throws exception-list

{
// body of method
}



Discussion

No Comment Found