I have been asked to add an exception class to the digital time problem that excepts two arguments an int value and an error message. I think I have a problem with the catch parameters or maybe the throw statement itself. because when my program encounters an error it crashes. Even the catch(...) does nothing. Do I have a another simple mistake that I just don't see? Or is it something bigger?
#include <string>
#include "DigitalTimeException.h"
usingnamespace std;
DigitalTimeException::DigitalTimeException(int value, string whatWentWrong)
{
// Set the stored message within the object
// Any text or int value will be accepted as the error message
message = whatWentWrong;
num = value;
}
// Return the error message stored inside the object
string DigitalTimeException::errorMessage()
{
return message;
}
// Return the error number stored inside the object
int DigitalTimeException::errorNumber()
{
return num;
}
the function from dtime.cpp that is supposed to throw the error
I just figured out the problem. The other functions that take DigitalTime as an input still had the if statements and exit sequence. I changed them to throw statements and now it works. I was under the impression that I could change the functions one at a time and test them as I go. But after thinking about it for a moment it makes sense why I cant do that.