Include originating function in C-API catch-all exception message#29561
Open
GopalakrishnanN wants to merge 3 commits into
Open
Include originating function in C-API catch-all exception message#29561GopalakrishnanN wants to merge 3 commits into
GopalakrishnanN wants to merge 3 commits into
Conversation
The terminal 'catch (...)' in API_IMPL_END returned ORT_FAIL with the literal 'Unknown Exception', discarding all context for any non-std::exception throwable that crosses the C ABI. Include the originating C-API function name via MakeString(..., __func__) so the returned OrtStatus points at where the unknown exception surfaced. Only the catch-all diagnostic message changes; all other handlers and normal paths are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The terminal
catch (...)handler in theAPI_IMPL_ENDmacro returnedORT_FAILwith the literal string"Unknown Exception":For any non-
std::exceptionthrowable that crosses the C ABI (rare, but e.g. a thrown integer from third-party code), this discarded all context, including which C-API function it surfaced in. This change records the originating function viaMakeString(..., __func__):API_IMPL_ENDexpands at the end of each C-API function body, so__func__resolves to the function where the unknown exception was caught.MakeStringis already available (error_code_helper.hincludescore/common/make_string.h), andCreateStatuscopies the message, so the temporary is safe.Only the catch-all diagnostic message changes. The
OnnxRuntimeException/NotImplementedException/std::exceptionhandlers and all normal execution paths are unaffected.Motivation and Context
Small diagnostic improvement flagged in an error-handling review (item EH3): the catch-all funnel collapsed to a context-free string, making a non-
std::exceptionfailure that reaches the C ABI hard to localize. Naming the originating function turns "something threw somewhere" into "something threw inOrtApiName".Testing
Built
onnxruntime_test_all(Release, Windows) — compiles cleanly across the C-API translation units that useAPI_IMPL_END;InferenceSessionTestssmoke test passes on the rebuilt binary.Note: the
catch (...)path fires only for a non-std::exceptionthrowable, which cannot be triggered from a unit test without editing production code, so this is a compile-verified diagnostic-only change.