From: Greg C. <gch...@sb...> - 2008-09-09 14:49:55
|
On 2008-09-09 14:31Z, newthinker wrote: > > if (hw.size() == 0) > throw domain_error("student has done no homework"); > > But the message has nothing to do with what I meant it to be, always > it is just: > > This application has requested the Runtime to terminate it in an unusual way. When an exception isn't caught, terminate() is called. You need to catch the exception and print it yourself; for exceptions derived from std::exception, use what() as in this example: /tmp[0]$cat throw_catch.cpp #include <exception> #include <iostream> #include <stdexcept> int main() { try { throw std::runtime_error("foo"); } catch(std::exception const& e) { std::cout << "Caught '" << e.what() << "'.\n"; } } /tmp[0]$g++ throw_catch.cpp /tmp[0]$./a Caught 'foo'. |