What is a throw in an Exception block?
- All methods use the 'throw' statement to throw an exception.
- Any code can throw an exception.
- The 'throw' requires a single argument that is a throwable object.
- These throwable objects are instances of any subclass of the 'Throwable class'.
Syntax: throw AnyThrowableException;
Example:if(condition)
{
throw new xxxException();
}
method_name throws xxxException
- There is a difference between 'throw' and 'throws' : 'throws' is used to postpone the handling of a checked exception and 'throw' is used to invoke an exception explicitly.