You are on page 1of 8

EXPERIMENT NUMBER –Practical 8.

1
STUDENT’S NAME – Aryaman Sharma

STUDENT’S UID – 20BCS4206

CLASS AND GROUP – 20CC2 AND B

SEMESTER – 2

TOPIC OF EXPERIMENT –

Learn how to use exception handling in C ++

AIM OF THE EXPERIMENT –

WAP to perform exception handling for Divide by zero Exception.

ALGORITHM –

1. Start the program.

2. Declare a function handle with an argument test.

3. In the try block, check the condition (if the test = 0 or 1 or 2). Then throw the
respective statement.

4. Catch the expectation (using catch all) and display the appropriate message.

5. End.

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
PROGRAM CODE –

#include <iostream>
using namespace std;

double division(int a, int b)


{
if( b == 0 )
{
throw "Division by zero condition!";

return (a/b);

int main ()
{
int x = 50;
int y = 0;
double z = 0;

try
{
z = division(x, y);
cout<< z <<endl;

}
catch (const char* msg)
{
cout<< msg <<endl;
}

return 0;

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION –

<-----No Error Occurred----->

OUTPUT –

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
EXPERIMENT NUMBER –Practical 8.1
STUDENT’S NAME – Aryaman Sharma

STUDENT’S UID – 20BCS4206

CLASS AND GROUP – 20CC2 AND B

SEMESTER – 2

TOPIC OF EXPERIMENT –

Learn how to use exception handling in C ++

AIM OF THE EXPERIMENT –


WAP to implement the exception handling with the functionality of testing the throw
restrictions.

ALGORITHM –

1. Start the program.

2. Declare a function and pass arguments, and in the main function, declare the
variables x, y, z and initialize them with their respective values.

3. In the try block, if the condition is true then throw the statement. ( if b=0 then
the number can’t divisible with 0.)

4. Catch the expectation and display the appropriate message.

5. End.

PROGRAM CODE –
SUBJECT NAME- OBJECT ORIENTED PROGRAMMING
USING C++ LAB
SUBJECT CODE-CSP-152
SUBJECT NAME- OBJECT ORIENTED PROGRAMMING
USING C++ LAB
SUBJECT CODE-CSP-152
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION –

<-----No Error Occurred----->

OUTPUT –

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
LEARNING OUTCOMES
 Identify situations where computational methods would be useful.

 Approach the programming tasks using techniques learnt and write pseudo-code.

 Choose the right data representation formats based on the requirements of the problem.

 Use the comparisons and limitations of the various programming constructs and choose
the right one for the task.

EVALUATION COLUMN (To be filled by concerned faculty only)

Sr. No. Parameters Maximum Marks


Marks Obtained
1. Worksheet Completion including writing 10
learning objective/ Outcome
2. Post Lab Quiz Result 5

3. Student engagement in Simulation/ 5


Performance/ Pre Lab Questions
4. Total Marks 20

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152

You might also like