IexBaseExc.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2002-2012, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. //---------------------------------------------------------------------
  35. //
  36. // Constructors and destructors for our exception base class.
  37. //
  38. //---------------------------------------------------------------------
  39. #include "IexExport.h"
  40. #include "IexBaseExc.h"
  41. #include "IexMacros.h"
  42. #ifdef PLATFORM_WINDOWS
  43. #include <windows.h>
  44. #endif
  45. #include <stdlib.h>
  46. IEX_INTERNAL_NAMESPACE_SOURCE_ENTER
  47. namespace {
  48. StackTracer currentStackTracer = 0;
  49. } // namespace
  50. void
  51. setStackTracer (StackTracer stackTracer)
  52. {
  53. currentStackTracer = stackTracer;
  54. }
  55. StackTracer
  56. stackTracer ()
  57. {
  58. return currentStackTracer;
  59. }
  60. BaseExc::BaseExc (const char* s) throw () :
  61. _message (s? s: ""),
  62. _stackTrace (currentStackTracer? currentStackTracer(): "")
  63. {
  64. // empty
  65. }
  66. BaseExc::BaseExc (const std::string &s) throw () :
  67. _message (s),
  68. _stackTrace (currentStackTracer? currentStackTracer(): "")
  69. {
  70. // empty
  71. }
  72. BaseExc::BaseExc (std::stringstream &s) throw () :
  73. _message (s.str()),
  74. _stackTrace (currentStackTracer? currentStackTracer(): "")
  75. {
  76. // empty
  77. }
  78. BaseExc::BaseExc (const BaseExc &be) throw () :
  79. _message (be._message),
  80. _stackTrace (be._stackTrace)
  81. {
  82. // empty
  83. }
  84. BaseExc::~BaseExc () throw ()
  85. {
  86. // empty
  87. }
  88. const char *
  89. BaseExc::what () const throw ()
  90. {
  91. return _message.c_str();
  92. }
  93. BaseExc &
  94. BaseExc::assign (std::stringstream &s)
  95. {
  96. _message.assign (s.str());
  97. return *this;
  98. }
  99. BaseExc &
  100. BaseExc::append (std::stringstream &s)
  101. {
  102. _message.append (s.str());
  103. return *this;
  104. }
  105. const std::string &
  106. BaseExc::message() const
  107. {
  108. return _message;
  109. }
  110. BaseExc &
  111. BaseExc::operator = (std::stringstream &s)
  112. {
  113. return assign (s);
  114. }
  115. BaseExc &
  116. BaseExc::operator += (std::stringstream &s)
  117. {
  118. return append (s);
  119. }
  120. BaseExc &
  121. BaseExc::assign (const char *s)
  122. {
  123. _message.assign(s);
  124. return *this;
  125. }
  126. BaseExc &
  127. BaseExc::operator = (const char *s)
  128. {
  129. return assign(s);
  130. }
  131. BaseExc &
  132. BaseExc::append (const char *s)
  133. {
  134. _message.append(s);
  135. return *this;
  136. }
  137. BaseExc &
  138. BaseExc::operator += (const char *s)
  139. {
  140. return append(s);
  141. }
  142. const std::string &
  143. BaseExc::stackTrace () const
  144. {
  145. return _stackTrace;
  146. }
  147. IEX_INTERNAL_NAMESPACE_SOURCE_EXIT
  148. #ifdef PLATFORM_WINDOWS
  149. #pragma optimize("", off)
  150. void
  151. iex_debugTrap()
  152. {
  153. if (0 != getenv("IEXDEBUGTHROW"))
  154. ::DebugBreak();
  155. }
  156. #else
  157. void
  158. iex_debugTrap()
  159. {
  160. // how to in Linux?
  161. if (0 != ::getenv("IEXDEBUGTHROW"))
  162. __builtin_trap();
  163. }
  164. #endif