utility.h 598 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #if __EXCEPTIONS
  5. # include <new>
  6. #endif // __EXCEPTIONS
  7. #include <string>
  8. #include "opentelemetry/version.h"
  9. OPENTELEMETRY_BEGIN_NAMESPACE
  10. namespace plugin
  11. {
  12. namespace detail
  13. {
  14. inline void CopyErrorMessage(const char *source, std::string &destination) noexcept
  15. #if __EXCEPTIONS
  16. try
  17. #endif
  18. {
  19. if (source == nullptr)
  20. {
  21. return;
  22. }
  23. destination.assign(source);
  24. }
  25. #if __EXCEPTIONS
  26. catch (const std::bad_alloc &)
  27. {}
  28. #endif
  29. } // namespace detail
  30. } // namespace plugin
  31. OPENTELEMETRY_END_NAMESPACE