throw.hpp 811 B

123456789101112131415161718192021222324252627282930313233343536
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018 Intel Corporation
  6. #ifndef OPENCV_GAPI_UTIL_THROW_HPP
  7. #define OPENCV_GAPI_UTIL_THROW_HPP
  8. #include <utility> // std::forward
  9. #if !defined(__EXCEPTIONS)
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #endif
  13. namespace cv
  14. {
  15. namespace util
  16. {
  17. template <class ExceptionType>
  18. [[noreturn]] void throw_error(ExceptionType &&e)
  19. {
  20. #if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
  21. throw std::forward<ExceptionType>(e);
  22. #else
  23. fprintf(stderr, "An exception thrown! %s\n" , e.what());
  24. fflush(stderr);
  25. abort();
  26. #endif
  27. }
  28. } // namespace util
  29. } // namespace cv
  30. #endif // OPENCV_GAPI_UTIL_THROW_HPP