What is a throw in an Exception block?

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.
What are Chained Exceptions?
What are Chained Exceptions? - When an application responds to an exception by throwing another exception, it is very useful to know when an exception caused another...
What is the purpose of the finally clause of a try-catch-finally statement?
Purpose of the finally clause - The finally block is the region where the code that needs to be executed under any circumstance is written...
Purpose of Event object
Purpose of Event object - EventObjects represent events. Applications subclass this class to add event specific information...
Post your comment