Skip to content

Remove debugreturn.h and machinery around preventing returns #116563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 16, 2025
15 changes: 7 additions & 8 deletions docs/design/coreclr/botr/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ The basic macros are, of course, EX_TRY / EX_CATCH / EX_END_CATCH, and in use th
EX_CATCH
// If we're here, something failed.
m_finalDisposition = terminallyHopeless;
EX_END_CATCH(RethrowTransientExceptions)
RethrowTransientExceptions();
EX_END_CATCH

The EX_TRY macro simply introduces the try block, and is much like the C++ "try", except that it also includes an opening brace, "{".

Expand Down Expand Up @@ -70,7 +71,8 @@ More information is often most conveniently available through the managed except
// . . . do something that might throw
EX_CATCH
throwable = GET_THROWABLE();
EX_END_CATCH(RethrowTransientExceptions)
RethrowTransientExceptions();
EX_END_CATCH
// . . . do something with throwable
GCPROTECT_END()

Expand All @@ -81,12 +83,11 @@ Sometimes, there is no avoiding a need for the C++ exception object, though this

would tell whether the exception is (or derives from) CLRException.

EX_END_CATCH(RethrowTransientExceptions)
RethrowTransientExceptions
----------------------------------------

In the example above, "RethrowTransientExceptions" is an argument to the EX_END_CATCH macro; it is one of three pre-defined macros that can be thought of "exception disposition". Here are the macros, and their meanings:
In the example above, "RethrowTransientExceptions" is a macro in the `EX_CATCH` block; it is one of three pre-defined macros that can be thought of "exception disposition". Here are the macros, and their meanings:

- _SwallowAllExceptions_: This is aptly named, and very simple. As the name suggests, it swallows everything. While simple and appealing, this is often not the right thing to do.
- _RethrowTerminalExceptions_. A better name would be "RethrowThreadAbort", which is what this macro does.
- _RethrowTransientExceptions_. The best definition of a "transient" exception is one that might not occur if tried again, possibly in a different context. These are the transient exceptions:
- COR_E_THREADABORTED
Expand All @@ -102,9 +103,7 @@ In the example above, "RethrowTransientExceptions" is an argument to the EX_END_

The CLR developer with doubts about which macro to use should probably pick _RethrowTransientExceptions_.

In every case, however, the developer writing an EX_END_CATCH needs to think hard about which exception should be caught, and should catch only those exceptions. And, because the macros catch everything anyway, the only way to not catch an exception is to rethrow it.

If an EX_CATCH / EX_END_CATCH block has properly categorized its exceptions, and has rethrown wherever necessary, then SwallowAllExceptions is the way to tell the macros that no further rethrowing is necessary.
In every case, however, the developer writing an EX_CATCH block needs to think hard about which exception should be caught, and should catch only those exceptions. And, because the macros catch everything anyway, the only way to not catch an exception is to rethrow it.

## EX_CATCH_HRESULT

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/binder/assemblybindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder
hr = GET_EXCEPTION()->GetHR();
goto Exit;
}
EX_END_CATCH(SwallowAllExceptions);
EX_END_CATCH


mvidMismatch = incomingMVID != boundMVID;
Expand Down
Loading
Loading