exception.cpp 688 B

1234567891011121314151617181920212223242526272829303132
  1. #include "config.h"
  2. #include "exception.h"
  3. #include <cassert>
  4. #include <string>
  5. EaxException::EaxException(std::string_view context, std::string_view message)
  6. : std::runtime_error{make_message(context, message)}
  7. {
  8. }
  9. EaxException::~EaxException() = default;
  10. std::string EaxException::make_message(std::string_view context, std::string_view message)
  11. {
  12. auto what = std::string{};
  13. if(context.empty() && message.empty())
  14. return what;
  15. what.reserve((!context.empty() ? context.size() + 3 : 0) + message.length() + 1);
  16. if(!context.empty())
  17. {
  18. what += "[";
  19. what += context;
  20. what += "] ";
  21. }
  22. what += message;
  23. return what;
  24. }