| 29 | namespace nvcv::priv { |
| 30 | |
| 31 | void SetThreadError(std::exception_ptr e) |
| 32 | { |
| 33 | CoreTLS &tls = GetCoreTLS(); |
| 34 | |
| 35 | const int errorMessageLen = sizeof(tls.lastErrorMessage) - 1; |
| 36 | |
| 37 | try |
| 38 | { |
| 39 | if (e) |
| 40 | { |
| 41 | rethrow_exception(e); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | tls.lastErrorStatus = NVCV_SUCCESS; |
| 46 | snprintf(tls.lastErrorMessage, errorMessageLen, "success"); |
| 47 | } |
| 48 | } |
| 49 | catch (const ::nvcv::Exception &e) |
| 50 | { |
| 51 | tls.lastErrorStatus = NVCV_ERROR_INTERNAL; |
| 52 | NVCV_ASSERT(!"Exception from public API cannot be originated from internal library implementation"); |
| 53 | } |
| 54 | catch (const Exception &e) |
| 55 | { |
| 56 | tls.lastErrorStatus = e.code(); |
| 57 | snprintf(tls.lastErrorMessage, errorMessageLen, "%s", e.msg()); |
| 58 | } |
| 59 | catch (const std::invalid_argument &e) |
| 60 | { |
| 61 | tls.lastErrorStatus = NVCV_ERROR_INVALID_ARGUMENT; |
| 62 | snprintf(tls.lastErrorMessage, errorMessageLen, "%s", e.what()); |
| 63 | } |
| 64 | catch (const std::bad_alloc &) |
| 65 | { |
| 66 | tls.lastErrorStatus = NVCV_ERROR_OUT_OF_MEMORY; |
| 67 | snprintf(tls.lastErrorMessage, errorMessageLen, "Not enough space for resource allocation"); |
| 68 | } |
| 69 | catch (const std::exception &e) |
| 70 | { |
| 71 | tls.lastErrorStatus = NVCV_ERROR_INTERNAL; |
| 72 | snprintf(tls.lastErrorMessage, errorMessageLen, "%s", e.what()); |
| 73 | } |
| 74 | catch (...) |
| 75 | { |
| 76 | tls.lastErrorStatus = NVCV_ERROR_INTERNAL; |
| 77 | snprintf(tls.lastErrorMessage, errorMessageLen, "Unexpected error"); |
| 78 | } |
| 79 | |
| 80 | tls.lastErrorMessage[errorMessageLen] = '\0'; // Make sure it's null-terminated |
| 81 | } |
| 82 | |
| 83 | NVCVStatus GetLastThreadError() noexcept |
| 84 | { |
no test coverage detected