Edit: there's nothing wrong with the book, I simply failed to properly copy the code provided in it. The try-catch
block is supposed to be inside the while loop while I've put it outside of it.
There is something I may be missing about Stroutrup's "Programming: Principles and Practice using C++", at chapter 7, section 7 ("Recovering from errors"). I hope someone who read this book will be able to help me (or anyone, actually!).
We have developed a calculator with a token parser. When the program reads an invalid token, it just terminates. Section 7' objective is to make the calculator recover from such errors without terminating. My problem is that after following the book's directives, the calculator still terminates after an invalid token.
Here is the complete code of the calculator. Here is std_lib_facilities.h, in case you need it to understand the code.
As you can see, main()
calls for calculate()
, which in turn calls for clean_up_mess()
if an exception is thrown (which happens when a invalid token is read). clean_up_mess()
then removes everything from the Token_stream until the print char (';') is found, so we can go on with the next calculation, which will hopefully not contain another invalid token.
But after the exception handling is done, the program simply terminates. What do I need to do for it to resume where the exception was thrown? And did the author forget to explain this, or did I miss something?
Thanks.