I'm new to programming, and when I try to use exception handling, I got an error in code block 16:01
ending a call after calling the instance of 'char const *'
this is mistake.
can someone help me with this error, I tried to reset the default IDE but did not work
code
#include <iostream> #include <cmath> #include <stdexcept> using namespace std; double sqrt(double num) { if(num < 0) throw "Negative number is not allowed"; double x = pow(num,0.5); return x; } int main() { double x; cout <<"Enter a number : "; cin >> x; double num; try { num = sqrt(x); } catch(const char *text) { cout << "ERROR : "<<text<<endl; return 1; } cout <<"Square root of "<< num <<" is : "<<num; return 0; }
loody source share