############################################################################ cErrorReporter ############################################################################
| 51 | // cErrorReporter |
| 52 | //############################################################################# |
| 53 | void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra) |
| 54 | { |
| 55 | cDisplayEncoder e((cDisplayEncoder::Flags)(cDisplayEncoder::NON_ROUNDTRIP | cDisplayEncoder::ALLOW_WHITESPACE)); |
| 56 | TSTRING errStr; |
| 57 | |
| 58 | // |
| 59 | // if the ID is zero, just return. |
| 60 | // this should only occur at the top level of a program (ie -- twcmdline.cpp) and |
| 61 | // indicates that an error occurred and an error message has already been printed out. |
| 62 | // Therefore, we will do nothing here but return. |
| 63 | // |
| 64 | |
| 65 | // TODO: Having an error with an ID of 0 is legacy. The only place it happens at this |
| 66 | // point is when we throw ePoly() with no constructor arguments. At some point we want |
| 67 | // to stop using the mechanism have non-printing errors, thus we leave in the ASSERT below. |
| 68 | // But we don't want to break any release code, thus we return on the next line - June 2, 1999 DMB. |
| 69 | ASSERT(error.GetID() != 0); |
| 70 | |
| 71 | if (error.GetID() == 0) |
| 72 | return; |
| 73 | |
| 74 | // "First Part" header |
| 75 | errStr = TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_ERROR : core::STR_ERROR_WARNING); |
| 76 | |
| 77 | if (errStr.empty()) |
| 78 | { |
| 79 | TOSTRINGSTREAM strm; |
| 80 | ASSERT(sizeof(uint32) == sizeof(unsigned int)); // for cast on next line |
| 81 | strm << _T("Unknown Error ID ") << (unsigned int)error.GetID(); |
| 82 | errStr = strm.str(); |
| 83 | } |
| 84 | |
| 85 | //int len = errStr.length(); // save for later |
| 86 | TCERR << errStr; |
| 87 | |
| 88 | // "First Part" error string |
| 89 | TSTRING prependToSecond; |
| 90 | |
| 91 | // #pragma message("errorbucketimpl.cpp needs a little help in the mb arena, with the findfirst/last and such") |
| 92 | |
| 93 | errStr = cErrorTable::GetInstance()->Get(error.GetID()); |
| 94 | if (!errStr.empty()) |
| 95 | { |
| 96 | // If the first part has a '\n' in it, we take everything following and prepend it to the |
| 97 | // second part. This was added to allow specifing a verbose string as the second part |
| 98 | // of an error message when building the error table. This change was made on July 27, 1999 |
| 99 | TSTRING::size_type firstLF; |
| 100 | if ((firstLF = errStr.find_first_of(_T('\n'))) != TSTRING::npos) |
| 101 | { |
| 102 | prependToSecond = errStr.substr(firstLF + 1); // don't include '\n' in new string |
| 103 | errStr.erase(firstLF); |
| 104 | } |
| 105 | |
| 106 | ASSERT(errStr.length() + len + 6 < 80); // line too big for terminal? |
| 107 | // Add 6 to account for "### ' and ': ' |
| 108 | TCERR << TSS_GetString(cCore, core::STR_ERROR_COLON) << _T(" ") << errStr; |
| 109 | TCERR << std::endl; |
| 110 | } |