What is an error ? An error is a term used to describe any issue that arises unexpectedly and result in incorrect output. Types of Errors There are two types of errors 1. Compile time error ( syntax error) e. g , ; () 2. Run time error (logical error)
What is an Exception? § Exceptions are run time anomalies or unusual conditions that a program may encounter while executing.
EXCEPTION HANDLING MECHANISM § It provides to detect and report exception circumstances: • Find the problem( Hit the exception) • Inform that an error has occurred (Throw the exception) • Receive the error information(Catch the exception) • Take corrective actions(handle the exceptions)
The Exception Handling Mechanism is built upon three keywords: q TRY § It used to preface a block of statements which may generate exceptions q Throw § When an exception is detected , it is thrown using a throw statement in try block.
q. Catch § A catch block defined by the keyword catches the exception thrown by the throw statement in the try block and handles it appropriately.
EXCEPTION HANDLING MECHANISM § When the try block throws the exception the program control leaves the try block and enters the catch statement of the catch block. § Otherwise the program is terminated