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

Add missing exception holder to EX_TRY #1878

Merged
merged 1 commit into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/inc/ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

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

#ifdef FEATURE_PAL
#define EX_TRY_HOLDER \
NativeExceptionHolderCatchAll __exceptionHolder; \
__exceptionHolder.Push(); \

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to use another non-templated derived class of NativeExceptionHolderBase that overrides InvokeFilter to return EXCEPTION_EXECUTE_HANDLER.

class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase
{

public:
    NativeExceptionHolderCatchAll()
        : NativeExceptionHolderBase()
    {
        Push();
    }

    virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
    {
        return EXCEPTION_EXECUTE_HANDLER;
    }
};

So then the EX_TRY_HOLDER can be just:
auto NativeExceptionHolderCatchAll __exceptionHolder;

#else // FEATURE_PAL
#define EX_TRY_HOLDER
#endif // FEATURE_PAL

#ifdef CLR_STANDALONE_BINDER

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

void DECLSPEC_NORETURN ThrowLastError();

#define EX_TRY try
#define EX_CATCH_HRESULT(_hr) catch (HRESULT hr) { _hr = hr; }
#define EX_CATCH catch(...)
#define EX_TRY \
try \
{ \
EX_TRY_HOLDER \

#define EX_CATCH_HRESULT(_hr) } catch (HRESULT hr) { _hr = hr; }
#define EX_CATCH } catch(...)
#define EX_END_CATCH(a)
#define EX_RETHROW throw
#define EX_SWALLOW_NONTERMINAL catch(...) {}
#define EX_SWALLOW_NONTERMINAL } catch(...) {}
#define EX_END_CATCH_UNREACHABLE
#define EX_CATCH_HRESULT_NO_ERRORINFO(_hr) \
EX_CATCH \
Expand Down Expand Up @@ -982,6 +995,7 @@ Exception *ExThrowWithInnerHelper(Exception *inner);
{ \
/* this is necessary for Rotor exception handling to work */ \
DEBUG_ASSURE_NO_RETURN_BEGIN(EX_TRY) \
EX_TRY_HOLDER \


#define EX_CATCH_IMPL_EX(DerivedExceptionClass) \
Expand Down
19 changes: 19 additions & 0 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6796,6 +6796,25 @@ class NativeExceptionHolder : public NativeExceptionHolderBase
}
};

//
// This is a native exception holder that is used when the catch catches
// all exceptions.
//
class NativeExceptionHolderCatchAll : public NativeExceptionHolderBase
{

public:
NativeExceptionHolderCatchAll()
: NativeExceptionHolderBase()
{
}

virtual EXCEPTION_DISPOSITION InvokeFilter(PAL_SEHException& ex)
{
return EXCEPTION_EXECUTE_HANDLER;
}
};

//
// This factory class for the native exception holder is necessary because
// templated functions don't need the explicit type parameter and can infer
Expand Down