-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
Unlike WIN32_ERROR, NTSTATUS and HRESULT are projected as structs instead of enums. As individual error codes are not constant expressions, they cannot be used in switch statements:
if (status == NTSTATUS.STATUS_SUCCESS || status == NTSTATUS.STATUS_PENDING || status == NTSTATUS.STATUS_MORE_ENTRIES || status == NTSTATUS.STATUS_BUFFER_TOO_SMALL)
{
// No error occurred, so exit gracefully.
return status;
}
if (status == NTSTATUS.STATUS_INVALID_PARAMETER)
{
throw new ArgumentException();
}Describe the solution you'd like
With enums, switch statements can be used, which simplifies the code:
switch (error)
{
case WIN32_ERROR.ERROR_DS_INVALID_DN_SYNTAX:
case WIN32_ERROR.ERROR_INVALID_PARAMETER:
case WIN32_ERROR.ERROR_INVALID_NAME:
case WIN32_ERROR.ERROR_BAD_ARGUMENTS:
case WIN32_ERROR.ERROR_INVALID_FLAG_NUMBER:
case WIN32_ERROR.ERROR_INVALID_ADDRESS:
exceptionToThrow = new ArgumentException(genericException.Message, genericException);
break;
case WIN32_ERROR.ERROR_ARITHMETIC_OVERFLOW:
exceptionToThrow = new ArithmeticException(genericException.Message, genericException);
break;
case WIN32_ERROR.ERROR_BAD_EXE_FORMAT:
exceptionToThrow = new BadImageFormatException(genericException.Message, genericException);
break;
case WIN32_ERROR.ERROR_BAD_FORMAT:
case WIN32_ERROR.ERROR_SXS_MANIFEST_PARSE_ERROR:
case WIN32_ERROR.ERROR_INVALID_DATA:
case WIN32_ERROR.ERROR_DATATYPE_MISMATCH:
exceptionToThrow = new FormatException(genericException.Message, genericException);
break;
...
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request