You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/design/coreclr/botr/exceptions.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,8 @@ The basic macros are, of course, EX_TRY / EX_CATCH / EX_END_CATCH, and in use th
31
31
EX_CATCH
32
32
// If we're here, something failed.
33
33
m_finalDisposition = terminallyHopeless;
34
-
EX_END_CATCH(RethrowTransientExceptions)
34
+
RethrowTransientExceptions();
35
+
EX_END_CATCH
35
36
36
37
The EX_TRY macro simply introduces the try block, and is much like the C++ "try", except that it also includes an opening brace, "{".
37
38
@@ -70,7 +71,8 @@ More information is often most conveniently available through the managed except
70
71
// . . . do something that might throw
71
72
EX_CATCH
72
73
throwable = GET_THROWABLE();
73
-
EX_END_CATCH(RethrowTransientExceptions)
74
+
RethrowTransientExceptions();
75
+
EX_END_CATCH
74
76
// . . . do something with throwable
75
77
GCPROTECT_END()
76
78
@@ -81,12 +83,11 @@ Sometimes, there is no avoiding a need for the C++ exception object, though this
81
83
82
84
would tell whether the exception is (or derives from) CLRException.
83
85
84
-
EX_END_CATCH(RethrowTransientExceptions)
86
+
RethrowTransientExceptions
85
87
----------------------------------------
86
88
87
-
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:
89
+
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:
88
90
89
-
-_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.
90
91
-_RethrowTerminalExceptions_. A better name would be "RethrowThreadAbort", which is what this macro does.
91
92
-_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:
92
93
- COR_E_THREADABORTED
@@ -102,9 +103,7 @@ In the example above, "RethrowTransientExceptions" is an argument to the EX_END_
102
103
103
104
The CLR developer with doubts about which macro to use should probably pick _RethrowTransientExceptions_.
104
105
105
-
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.
106
-
107
-
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.
106
+
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.
0 commit comments