exception handling wap in C++

PHOTO EMBED

Tue Jan 03 2023 02:50:10 GMT+0000 (Coordinated Universal Time)

Saved by @berasumit611 #c++

#include <iostream> 
#include <cmath> 
using namespace std; 


int main() {

    // Find the square root of 'n' entered by the user.
    cout << "Program starts -->" << endl << endl;

    float n;

    cout << "Enter n: ";
    cin >> n;

    try {
        if (n < 0) {
            throw "The value of 'n' must be greater than or equal to 0. Please try again.";
        }

        float result = sqrt(n);
        cout << "Result: " << result << endl << endl;
    } catch (const char *msg) {
        cout << msg << endl << endl;
    }

    cout << "<-- Program ends" << endl;

    return 0;
}
content_copyCOPY

https://github.com/Internshala-Online-Trainings/programming-with-c-and-cpp-v2/blob/master/m4-diving-into-cpp-programming/m4-code challenges - solution/m4-t5-e3.cpp