Lab 2 - Exceptions Lab
Objective
Design and implement a program to demonstrate the use of exception handling in C++. This project will help you understand the concept of exceptions and their usage in C++.Ex: If the input is:
Requirements
Create a class called
DivideByZeroException
that inherits from theexception
class. This class will be used to handle divide-by-zero errors.Add a constructor to the
DivideByZeroException
class that takes aconst char*
message as a parameter and passes it to the basestd::exception
class constructor.Create a function called
safeDivision()
that takes two double values as parameters (numerator and denominator) and returns the result of their division as a double. The function should have the following signature:double safeDivision(double numerator, double denominator)
In the
safeDivision()
function, check if the denominator is zero. If it is, throw an instance of theDivideByZeroException
class with an appropriate error message. If it's not, return the division result.In the
main()
function, demonstrate the usage of thesafeDivision()
function with various input values. Take the input values from the user and display the results.Use a
try
-catch
block in themain()
function to catch anyDivideByZeroException
exceptions thrown by thesafeDivision()
function. If an exception is caught, display the error message from the exception.
Please note - this lab requires a separate header an implementation file for the classes
Deliverable
Upload the following:
Full source code (.cpp files or .txt files)
Screenshot of the Console with the code executing
2024 - Programming 3 / Data Structures - Author: Dr. Kevin Roark