Monday, 15 February 2010

c++ - Exception class -



c++ - Exception class -

so i'm doing class exception linked list, have no thought set in. example, if user wants delete element not exist in list, print out "sparse exception caught: element not found, delete fail", or "sparse exception caught: sparse matrix empty, printing failed". ok me way? if so, how print out message?

sparseexception::sparseexception () { } sparseexception::sparseexception (char *message) { if (strcmp(message, "delete")) cout << "sparse exception caught: element not found, delete fail"; else cout << "sparse exception caught: sparse matrix empty, printing failed"; } void sparseexception::printmessage () const { }

in sentiment exception should inherit std::exception or 1 of subclasses. give thought of interface should implement. need what methods instance(in fact what returns printmessage print). if want print exception's message, improve overload operator<<.

inheriting std::exception needed know catch(std::exception& ex) grab exception code threw.

c++ exception

No comments:

Post a Comment