@@ -467,35 +467,37 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary(
467467 hDevice) != hContext->getDevices ().end (),
468468 UR_RESULT_ERROR_INVALID_CONTEXT);
469469
470- ur_result_t Result = UR_RESULT_SUCCESS;
471-
472- std::unique_ptr<ur_program_handle_t_> RetProgram{
473- new ur_program_handle_t_{hContext, hDevice}};
474-
475- if (pProperties) {
476- if (pProperties->count > 0 && pProperties->pMetadatas == nullptr ) {
477- return UR_RESULT_ERROR_INVALID_NULL_POINTER;
478- } else if (pProperties->count == 0 && pProperties->pMetadatas != nullptr ) {
479- return UR_RESULT_ERROR_INVALID_SIZE;
470+ try {
471+ std::unique_ptr<ur_program_handle_t_> RetProgram{
472+ new ur_program_handle_t_{hContext, hDevice}};
473+
474+ if (pProperties) {
475+ if (pProperties->count > 0 && pProperties->pMetadatas == nullptr ) {
476+ return UR_RESULT_ERROR_INVALID_NULL_POINTER;
477+ } else if (pProperties->count == 0 &&
478+ pProperties->pMetadatas != nullptr ) {
479+ return UR_RESULT_ERROR_INVALID_SIZE;
480+ }
481+ UR_CHECK_ERROR (
482+ RetProgram->setMetadata (pProperties->pMetadatas , pProperties->count ));
480483 }
481- Result =
482- RetProgram->setMetadata (pProperties->pMetadatas , pProperties->count );
483- UR_ASSERT (Result == UR_RESULT_SUCCESS, Result);
484- }
485484
486- auto pBinary_string = reinterpret_cast <const char *>(pBinary);
487- if (size == 0 ) {
488- size = strlen (pBinary_string) + 1 ;
489- }
490-
491- UR_ASSERT (size, UR_RESULT_ERROR_INVALID_SIZE);
485+ auto pBinary_string = reinterpret_cast <const char *>(pBinary);
486+ if (size == 0 ) {
487+ size = strlen (pBinary_string) + 1 ;
488+ }
492489
493- Result = RetProgram->setBinary (pBinary_string, size);
494- UR_ASSERT (Result == UR_RESULT_SUCCESS, Result);
490+ UR_ASSERT (size, UR_RESULT_ERROR_INVALID_SIZE);
495491
496- *phProgram = RetProgram. release ( );
492+ UR_CHECK_ERROR ( RetProgram-> setBinary (pBinary_string, size) );
497493
498- return Result;
494+ *phProgram = RetProgram.release ();
495+ } catch (std::bad_alloc &) {
496+ return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
497+ } catch (...) {
498+ return UR_RESULT_ERROR_UNKNOWN;
499+ }
500+ return UR_RESULT_SUCCESS;
499501}
500502
501503// This entry point is only used for native specialization constants (SPIR-V),
0 commit comments