Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 018e85f

Browse files
committed
Add missing exception holder to EX_TRY
When the exception handling was changed recently, the exception holder was added only to PAL_TRY / PAL_EXCEPT macros. But it needs to be in the EX_TRY as well, otherwise first pass of exception handling would incorrectly consider some exceptions unhandled.
1 parent af48d72 commit 018e85f

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/inc/ex.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
void RetailAssertIfExpectedClean(); // Defined in src/utilcode/debug.cpp
1111

12+
#ifdef FEATURE_PAL
13+
#define EX_TRY_HOLDER \
14+
NativeExceptionHolderCatchAll __exceptionHolder; \
15+
__exceptionHolder.Push(); \
16+
17+
#else // FEATURE_PAL
18+
#define EX_TRY_HOLDER
19+
#endif // FEATURE_PAL
20+
1221
#ifdef CLR_STANDALONE_BINDER
1322

1423
#define INCONTRACT(x)
@@ -17,12 +26,16 @@ void RetailAssertIfExpectedClean(); // Defined in src/utilcode/debug
1726

1827
void DECLSPEC_NORETURN ThrowLastError();
1928

20-
#define EX_TRY try
21-
#define EX_CATCH_HRESULT(_hr) catch (HRESULT hr) { _hr = hr; }
22-
#define EX_CATCH catch(...)
29+
#define EX_TRY \
30+
try \
31+
{ \
32+
EX_TRY_HOLDER \
33+
34+
#define EX_CATCH_HRESULT(_hr) } catch (HRESULT hr) { _hr = hr; }
35+
#define EX_CATCH } catch(...)
2336
#define EX_END_CATCH(a)
2437
#define EX_RETHROW throw
25-
#define EX_SWALLOW_NONTERMINAL catch(...) {}
38+
#define EX_SWALLOW_NONTERMINAL } catch(...) {}
2639
#define EX_END_CATCH_UNREACHABLE
2740
#define EX_CATCH_HRESULT_NO_ERRORINFO(_hr) \
2841
EX_CATCH \
@@ -982,6 +995,7 @@ Exception *ExThrowWithInnerHelper(Exception *inner);
982995
{ \
983996
/* this is necessary for Rotor exception handling to work */ \
984997
DEBUG_ASSURE_NO_RETURN_BEGIN(EX_TRY) \
998+
EX_TRY_HOLDER \
985999

9861000

9871001
#define EX_CATCH_IMPL_EX(DerivedExceptionClass) \

src/pal/inc/pal.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6796,6 +6796,25 @@ class NativeExceptionHolder : public NativeExceptionHolderBase
67966796
}
67976797
};
67986798

6799+
//
6800+
// This is a native exception holder that is used when the catch catches
6801+
// all exceptions.
6802+
//
6803+
class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase
6804+
{
6805+
6806+
public:
6807+
NativeExceptionHolderCatchAll()
6808+
: NativeExceptionHolderBase()
6809+
{
6810+
}
6811+
6812+
virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
6813+
{
6814+
return EXCEPTION_EXECUTE_HANDLER;
6815+
}
6816+
};
6817+
67996818
//
68006819
// This factory class for the native exception holder is necessary because
68016820
// templated functions don't need the explicit type parameter and can infer

0 commit comments

Comments
 (0)