Handling exceptions is a good skill to learn as more and
more functions and classes throw exceptions when things go wrong.
Process
buffer04.hand
lab04main.cppJust In Case. Continue working with the originals.
By the way -- the UNIX/Linux copy command is cp and can be used like this:
cp buffer04.h buffer04.h.bak
#include<stdexcept>needed (book page 820) to both files. Include
using namespace std;Test the result with a quick recompilation and run of lab04main.cpp!
cout<< b[24]<<endl;
try{
assert( b[24] == '\0' );
}
catch(exception& e)
{
cerr << "Exception "<< typeid(e).name() << ": " << e.what();
}
int discard=0;and
discard++;somewhere. Figure out where inside operator>>.
try{...}catch(length_error&e){...}
block. Hint: put the try{ at the
start and catch(...){...} at the end of the main block.
Add another throw to the operator>> function to recognize enemy action:
more than 70 characters in a line. It should throw
runtime_error("Hacker Attacker!");