Error.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /***************************************************************************
  2. *
  3. * Project _____ __ ____ _ _
  4. * ( _ ) /__\ (_ _)_| |_ _| |_
  5. * )(_)( /(__)\ )( (_ _)(_ _)
  6. * (_____)(__)(__)(__) |_| |_|
  7. *
  8. *
  9. * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ***************************************************************************/
  24. #ifndef oatpp_async_Error_hpp
  25. #define oatpp_async_Error_hpp
  26. #include "oatpp/core/base/Countable.hpp"
  27. #include <string>
  28. namespace oatpp { namespace async {
  29. /**
  30. * Class to hold and communicate errors between Coroutines
  31. */
  32. class Error : public std::runtime_error, public oatpp::base::Countable {
  33. public:
  34. /**
  35. * Constructor.
  36. * @param what - error explanation.
  37. */
  38. explicit Error(const std::string& what);
  39. /**
  40. * Check if error belongs to specified class.
  41. * @tparam ErrorClass
  42. * @return - `true` if error is of specified class
  43. */
  44. template<class ErrorClass>
  45. bool is() const {
  46. return dynamic_cast<const ErrorClass*>(this) != nullptr;
  47. }
  48. };
  49. }}
  50. #endif //oatpp_async_Error_hpp