0% found this document useful (0 votes)
59 views

Group No.6: Sumeed Javed 1515 Muhammad Kashan 1493 Talha Asghar 1520

The document discusses exception handling in programming. It defines an exception as an unexpected event that disrupts normal program flow. It describes different types of exceptions and lists some examples. Exception handling separates error handling code from normal code to make programs more robust. The fundamentals are based on three keywords: try, catch, and throw. The try block contains code that may throw exceptions. Catch blocks catch specific exceptions, and throw throws exceptions. A sample program demonstrates throwing and catching a division by zero exception.

Uploaded by

Genghis Khan 69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Group No.6: Sumeed Javed 1515 Muhammad Kashan 1493 Talha Asghar 1520

The document discusses exception handling in programming. It defines an exception as an unexpected event that disrupts normal program flow. It describes different types of exceptions and lists some examples. Exception handling separates error handling code from normal code to make programs more robust. The fundamentals are based on three keywords: try, catch, and throw. The try block contains code that may throw exceptions. Catch blocks catch specific exceptions, and throw throws exceptions. A sample program demonstrates throwing and catching a division by zero exception.

Uploaded by

Genghis Khan 69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

GROUP NO.

6
Sumeed Javed 1515
Muhammad kashan 1493
Talha Asghar 1520
CONTENTS:
 Definition of exception
 Types of exceptions
 Exceptional handling definition
 Exceptional handling mechanism
 Diagram
 Exceptional handling mechanism
 Advantages/ Purpose
 Exceptional handling fundamentals
 Keywords
 Try definition
 Catch definition
 Throw definition
 Syntax of exceptional handling
 Block Diagram
 Program
PRESENTER NO.1

Sumeed Javed
Roll no.bsf1601515
BS(IT) 3rd
EXCEPTION:
 Definition:
“An exception is an unexpected event that occurs
during run-time and causes normal program flow to
be disrupted.”
 Definition:
“Exception is an run time anomalies or unusual
conditions that a program may encounter during
execution.”
EXAMPLE OF EXCEPTION:
 Divide by zero error.
 Accessing the elements of an
array beyond its range.
 Invalid input.
 Hard disk crash.
 Opening a non-existent file.
TYPES OF EXCEPTIONS:
 There are two types:
 Synchronous exception:
 Out of range
 Over flow
 Asynchronous exception: Error that are
caused by causes beyond the control of the
program
 Keyboard interrupts
 In C ++ only Synchronous exception can be
handled.
EXCEPTIONAL HANDLING:

 Definition:
 “The way of handling anomalous
situation in a program-run is known
as exception handling.”
EXCEPTIONAL HANDLING
MECHANISM:

 Find the problem.


 Inform that an error has occurred.
 Receive the error information.
 Take corrective action.
DIAGRAM:
EXCEPTIONAL HANDLING
ADVANTAGES:
Its advantages are:
 Exception handling separates error handling
code from normal code.
 It clarifies the code and enhance readability.
 It stimulates consequences as the error
handling takes place at one place and in one
manner.
 Its makes for clear robust and fault tolerant
programs.
EXCEPTIONAL HANDLING
FUNDAMENTALS:
 Codes that we want to monitor for exceptions
must have been executed from within try
block.
 Functions called from try block may also throw
an exception.
 Exception that can be thrown by the monitored
code are caught by a catch statement.
 Based on three key words:
 Try
 Catch
 Throw
PRESENTER NO.2
Muhammad Kashan Sarwar
Roll no.bsf1601493
BS(IT) 3rd
EXCEPTIONAL HANDLING
FUNDAMENTALS:
 As we know that exceptional handling
fundamentals based on three keywords.


Try

Catch

Throw
KEYWORDS:
 Try: “The keyword try is used to preface a
block of which may generate exceptions.”
 Throw: “When an exception is detected, it is
the thrown using a throw statement in the
try block.
 Catch: “A catch block define by the keyword
‘catch’ catches the exception and handles it
appropriately.
 The catch block that catches an exception
must immediately follow the try block that
throws the exceptions.
TASK OF EXCEPTION HANDLING
FUNDAMENTALS:
 Hit the exception
 Throw the exception
 Catch the exception
 Handling the exception
BLOCK DIAGRAM:
SYNTAX OF EXCEPTION
HANDLING:
try
{
… //block of statements
throw exception; //which detect and
… //throws an exception
}
catch (type arg) //catch exception
{
… //block of statements
… //that handles the
… //exception
}
PROGRAM:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b;
cout<<"Enter value of a and b"<<endl;
cin>>a>>b;
int x = a/(a-b);
cout<<"x="<<x<<endl;
getch();
return 0;
}
 #include<iostream>
 #include<conio.h>
 using namespace std;
 int main()
 {
 int a,b;
 cout<<"Enter value of a and b"<<endl;
 cin>>a>>b;
 int x = (a-b);
 try{
 if(x!=0){
 cout<<"result:"<<a/(a-b)<<endl;
 }
 else
 {
 throw(x);
 }
 }
 catch(int i){
 cout<<"division by zero"<<endl;
 }
 cout<<"next statement";
 getch();
 return 0;
 }

You might also like