I just started Programming: Principles and Practice Using C++ because I'm new to programming.
Errors and how to handle them are covered in one of the chapters.
What I'm attempting to implement is this little line of code.
The programme will end with a system error message and the text we gave as a parameter, according to the book's description of error().
#include <iostream>
#include <string>
using namespace std;
int area (int length, int width)
{
return length * width;
}
int framed_area (int x, int y)
{
return area(x-2, y-2);
}
inline void error(const string& s)
{
throw runtime_error(s);
}
int main()
{
int x = -1;
int y = 2;
int z = 4;
if(x<=0) error("non-positive x");
if(y<=0) error("non-positive y");
int area1 = area(x,y);
int area2 = framed_area(1,z);
int area3 = framed_area(y,z);
double ratio = double(area1)/area3;
system("PAUSE");
return EXIT_SUCCESS;
}
"Unhandled exception at 0x7699c41f in test project.exe: Microsoft C++ exception: std::runtime error at memory position 0x0038fc18," is the message I receive.
Therefore, I want to know why the message I send to error() isn't being sent. What am I doing wrong?