0% found this document useful (0 votes)
14 views3 pages

Lab 12

Uploaded by

abdulwhy99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Lab 12

Uploaded by

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

Lab #12: Exceptional Handling

Name: abdurahman

roll no 21

Semester: 2nd

Presentation/Procedure Code Comments Response Total


& conclusion
TASKS:
 Handling of division by zero exception.

#include <iostream>

#include <stdexcept>

using namespace std;

double divide(double numerator, double denominator) {

if (denominator == 0) {

throw runtime_error("Division by zero exception");

return numerator / denominator;

int main() {

double a, b;

cout << "Enter numerator: ";

cin >> a;

cout << "Enter denominator: ";

cin >> b;

try {

double result = divide(a, b);

cout << "Result: " << result << endl;

} catch (const runtime_error& e) {

cout << "Error: " << e.what() << endl;


}

return 0;

Explanation:

 Function divide: Performs division and throws a runtime error if the denominator is
zero.

Conclusion: This task demonstrates the use of exception handling to manage runtime errors
gracefully. It emphasizes the importance of validating inputs and handling exceptional cases
to ensure robust and error-free programs.

You might also like