Errors (Phone Bill Program)

How do I build the parameters so that my program can catch errors such as:

-Transactional code only the codes D and P - are permitted


-Transaction ammount - only double values are permitted

-Account number - only specific 6 digit account numbers are valid
(All of the above come up on the same line, and update periodically)


So there will be multiple lines, which method can I use to determine which line the error is on and the error at hand as well.

You could throw an exception and catch it, assert it, or use if statements.
@giblit, I'm very new could you elaborate a bit more please, I have no idea where to start

I have an idea of catching the different errors but, I don't know how I'd catch them at the line in which they occur.
I'm not sure how you have it setup but it could be something like this

1
2
3
4
5
6
7
8
9
10
try
{
    getCode(code);
    getAmount(amount);
    getNumber(number);
}
catch(std::exception &e)
{
    std::cerr << "exception caught: " << e.what() << std::endl;
}


Or something similar.

Try reading these
http://www.cplusplus.com/doc/tutorial/exceptions/
http://www.cplusplus.com/reference/cassert/assert/
http://www.learncpp.com/cpp-tutorial/712-handling-errors-assert-cerr-exit-and-exceptions/

Edit also learncpp.com chapter 15
Last edited on
Topic archived. No new replies allowed.