Bugcheck.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Bugcheck.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Bugcheck.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Core
  8. // Module: Bugcheck
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Bugcheck.h"
  16. #include "Poco/Debugger.h"
  17. #include "Poco/Exception.h"
  18. #include <sstream>
  19. namespace Poco {
  20. void Bugcheck::assertion(const char* cond, const char* file, int line, const char* text)
  21. {
  22. std::string message("Assertion violation: ");
  23. message += cond;
  24. if (text)
  25. {
  26. message += " (";
  27. message += text;
  28. message += ")";
  29. }
  30. Debugger::enter(message, file, line);
  31. throw AssertionViolationException(what(cond, file, line, text));
  32. }
  33. void Bugcheck::nullPointer(const char* ptr, const char* file, int line)
  34. {
  35. Debugger::enter(std::string("NULL pointer: ") + ptr, file, line);
  36. throw NullPointerException(what(ptr, file, line));
  37. }
  38. void Bugcheck::bugcheck(const char* file, int line)
  39. {
  40. Debugger::enter("Bugcheck", file, line);
  41. throw BugcheckException(what(0, file, line));
  42. }
  43. void Bugcheck::bugcheck(const char* msg, const char* file, int line)
  44. {
  45. std::string m("Bugcheck");
  46. if (msg)
  47. {
  48. m.append(": ");
  49. m.append(msg);
  50. }
  51. Debugger::enter(m, file, line);
  52. throw BugcheckException(what(msg, file, line));
  53. }
  54. void Bugcheck::unexpected(const char* file, int line)
  55. {
  56. #ifdef _DEBUG
  57. try
  58. {
  59. std::string msg("Unexpected exception in noexcept function or destructor: ");
  60. try
  61. {
  62. throw;
  63. }
  64. catch (Poco::Exception& exc)
  65. {
  66. msg += exc.displayText();
  67. }
  68. catch (std::exception& exc)
  69. {
  70. msg += exc.what();
  71. }
  72. catch (...)
  73. {
  74. msg += "unknown exception";
  75. }
  76. Debugger::enter(msg, file, line);
  77. }
  78. catch (...)
  79. {
  80. }
  81. #endif
  82. }
  83. void Bugcheck::debugger(const char* file, int line)
  84. {
  85. Debugger::enter(file, line);
  86. }
  87. void Bugcheck::debugger(const char* msg, const char* file, int line)
  88. {
  89. Debugger::enter(msg, file, line);
  90. }
  91. std::string Bugcheck::what(const char* msg, const char* file, int line, const char* text)
  92. {
  93. std::ostringstream str;
  94. if (msg) str << msg << " ";
  95. if (text != NULL) str << "(" << text << ") ";
  96. str << "in file \"" << file << "\", line " << line;
  97. return str.str();
  98. }
  99. } // namespace Poco