編譯器警告 (層級 4) C4843

' type1 ':無法連線到陣列或函式類型的參考例外狀況處理常式,請改用 ' type2 '

備註

陣列或函式類型參考的處理常式從未可以比對所有例外狀況物件。 從 Visual Studio 2017 15.5 版開始,編譯器會接受此規則,並引發層級 4 警告。 使用 時 /Zc:strictStrings ,它也不會再比對 或 wchar_t* 的處理常式 char* 與字串常值。

此警告是 Visual Studio 2017 15.5 版的新功能。 如需如何依編譯器版本停用警告的資訊,請參閱 編譯器版本的 編譯器警告。

範例

此範例顯示導致 C4843 的數個 catch 語句:

// C4843_warning.cpp
// compile by using: cl /EHsc /W4 C4843_warning.cpp
int main()
{
    try {
        throw "";
    }
    catch (int (&)[1]) {} // C4843 (This should always be dead code.)
    catch (void (&)()) {} // C4843 (This should always be dead code.)
    catch (char*) {} // This should not be a match under /Zc:strictStrings
}

編譯器會產生下列警告:

warning C4843: 'int (&)[1]': An exception handler of reference to array or function type is unreachable, use 'int*' instead
warning C4843: 'void (__cdecl &)(void)': An exception handler of reference to array or function type is unreachable, use 'void (__cdecl*)(void)' instead

下列程式碼可避免這個錯誤:

// C4843_fixed.cpp
// compile by using: cl /EHsc /W4 C4843_fixed.cpp
int main()
{
    try {
        throw "";
    }
    catch (int (*)[1]) {}
}