Exception: An unwanted unexpected event that disturbs the normal flow of the program is called an exception.
Example:
SleepingException
TyrePunchuredException
FileNotFoundException…..etc
• It is highly recommended to handle exceptions. The main objective of exception handling is graceful (normal) termination of the program.
What is the meaning of exception handling?
• Exception handling doesn’t mean repairing an exception. We have to define an alternative way to continue the rest of the program normally this way of “defining alternative is nothing but exception handling”.
Example: Suppose our programming requirement is to read data from London file at runtime if London file is not available our program should not be terminated abnormally. We have to provide a local file to continue the rest of the program normally. This way of defining alternative is
nothing but exception handling.
Example:
try
{
read data from london file
}
catch(FileNotFoundException e)
{
use local file and continue rest of the program normally
}
.
.
.
Comments
Post a Comment