Throw And Throws In Java
Chapter:
Exception Handling
Last Updated:
20-06-2016 16:25:34 UTC
Program:
/* ............... START ............... */
public class JavaThrowThrowsExample {
public void exceptionHandlingThrow() {
throw new ArithmeticException("Arithmetic Exception");
}
void exceptionHandlingThrows() throws ArithmeticException {
// method code
}
}
/* ............... END ............... */
Notes:
-
Java throw keyword is used to explicitly throw an exception.
- Java throws keyword is used to declare an exception.
- Throw is used within the method.
- Throws is used with the method signature.
Tags
Throw And Throws, Java, Exception Handling