SelfCheck Class
Provides methods to perform self-checks in library or application code.
public static class SelfCheckRemarks
The message of every exception created by this class names the assembly of the calling method, as the call stack reports it. When the JIT compiler removes the frame of the calling method, by inlining it into its own caller or by a tail call, the message names the assembly of the next frame instead.
Methods
| Name | Description |
|---|---|
| CriticalFailure(string, string, int) | Creates and returns a critical exception telling that an internal self-check has failed and the application should terminate immediately. |
| Fail(string, string, int) | Throws an exception telling that an internal self-check has failed. |
| Fail<T>(string, string, int) | Throws an exception telling that an internal self-check has failed. |
| FailCritically(string, string, int) | Throws a critical exception telling that an internal self-check has failed. |
| FailCritically<T>(string, string, int) | Throws a critical exception telling that an internal self-check has failed. |
| Failure(string, string, int) | Creates and returns an exception telling that an internal self-check has failed. |
CriticalFailure(string, string, int)
Creates and returns a critical exception telling that an internal self-check has failed and the application should terminate immediately.
public static CriticalInternalErrorException CriticalFailure(string message, string filePath = "", int lineNumber = 0)Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Returns
CriticalInternalErrorException A newly-created instance of CriticalInternalErrorException.
Remarks
The returned exception will be of type CriticalInternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.
The returned exception is of a type that will be considered a critical error by the Exception.IsCriticalError method; therefore, assuming critical error checks are implemented correctly, it will not be caught and will cause the application to terminate immediately.
See also
Fail overloads
Fail(string, string, int)
Throws an exception telling that an internal self-check has failed.
Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Remarks
The thrown exception will be of type InternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.
Fail<T>(string, string, int)
Throws an exception telling that an internal self-check has failed.
Type parameters
T- The expected return type.
Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Returns
T This method never returns.
Remarks
The thrown exception will be of type InternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.
FailCritically overloads
FailCritically(string, string, int)
Throws a critical exception telling that an internal self-check has failed.
Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Remarks
The thrown exception will be of type CriticalInternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.
The thrown exception is of a type that will be considered critical by the Exception.IsCriticalError method; therefore, assuming critical exception checks are implemented correctly, it will not be caught and will cause the application to terminate immediately.
FailCritically<T>(string, string, int)
Throws a critical exception telling that an internal self-check has failed.
Type parameters
T- The expected return type.
Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Returns
T This method never returns.
Remarks
The thrown exception will be of type CriticalInternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.
The thrown exception is of a type that will be considered critical by the Exception.IsCriticalError method; therefore, assuming critical exception checks are implemented correctly, it will not be caught and will cause the application to terminate immediately.
Failure(string, string, int)
Creates and returns an exception telling that an internal self-check has failed.
public static InternalErrorException Failure(string message, string filePath = "", int lineNumber = 0)Parameters
messagestring- The exception message.
filePathstring- The path of the source file where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
lineNumberint- The line number in source where this method is called. This parameter is automatically added by the compiler and should never be provided explicitly.
Returns
InternalErrorException A newly-created instance of InternalErrorException.
Remarks
The returned exception will be of type InternalErrorException; its Message property will contain the specified message, preceded by an indication of the assembly, source file, and line number of the failed check.