An Exception is an abnormal condition that arises in a code sequence at runtime. In simple way an exception is a runtime error.
Eg: If you use division operator i.e (a/b) in your code . if the value of b is zero then at run time the exception occurs as ‘divide by Zero’.
If you not handled the exception in your code the program will be error out . You can handle the exception using try-catch-finally method for safe completion of the program.
Syntax:
Example With out Exception Handling:
Output:
Example with Exception Handling:
Output:
Example of Finally block:
Output If the exception raises:
Output if there is no Exception:
Changed the value of b to 2
Will discuss more on Exception handling in later parts
Eg: If you use division operator i.e (a/b) in your code . if the value of b is zero then at run time the exception occurs as ‘divide by Zero’.
If you not handled the exception in your code the program will be error out . You can handle the exception using try-catch-finally method for safe completion of the program.
Syntax:
Example With out Exception Handling:
Output:

Example with Exception Handling:
Output:

Example of Finally block:
Output If the exception raises:

Output if there is no Exception:
Changed the value of b to 2

Will discuss more on Exception handling in later parts
No comments:
Post a Comment