Compiler Warning (level 4) C4843
'type1': An exception handler of reference to array or function type is unreachable, use 'type2' instead
Remarks
Handlers of reference to array or function type are never a match for any exception object. Starting in Visual Studio 2017 version 15.5, the compiler honors this rule and raises a level 4 warning. It also no longer matches a handler of char*
or wchar_t*
to a string literal when /Zc:strictStrings
is used.
This warning is new in Visual Studio 2017 version 15.5. For information on how to disable warnings by compiler version, see Compiler warnings by compiler version.
Example
This sample shows several catch
statements that cause C4843:
// 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
}
The compiler generates these warnings:
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
The following code avoids the error:
// C4843_fixed.cpp
// compile by using: cl /EHsc /W4 C4843_fixed.cpp
int main()
{
try {
throw "";
}
catch (int (*)[1]) {}
}
Обратна връзка
https://aka.ms/ContentUserFeedback.
Очаквайте скоро: През цялата 2024 г. постепенно ще отстраняваме проблемите в GitHub като механизъм за обратна връзка за съдържание и ще го заменим с нова система за обратна връзка. За повече информация вижте:Подаване и преглед на обратна връзка за