J
Joe Hesse
What do I have to do to the following program to catch the runtime error?
Many thanks,
Joe Hesse
------------------------------------------------
#include <iostream>
#include <stdexcept>
using namespace std;
void f()
{
int x = 1, y = 0, z;
z = x/y; // divide by zero
}
int main()
{
try
{
f(); // function has a runtime error
}
catch(const runtime_error &re)
{
cerr << re.what() << "\n";
}
catch(...)
{
cerr << "Caught ..." << "\n";
}
return 0;
}
------------------------------------------------
Many thanks,
Joe Hesse
------------------------------------------------
#include <iostream>
#include <stdexcept>
using namespace std;
void f()
{
int x = 1, y = 0, z;
z = x/y; // divide by zero
}
int main()
{
try
{
f(); // function has a runtime error
}
catch(const runtime_error &re)
{
cerr << re.what() << "\n";
}
catch(...)
{
cerr << "Caught ..." << "\n";
}
return 0;
}
------------------------------------------------