/// <summary> /// Creates a new WinSysException from the specified error code. The message is automatically set to the SysErrorCode /// <see cref="DisplayValueAttribute">Display</see> and <see cref="DataValueAttribute">Data</see> /// attributes. /// </summary> /// <param name="errorCode">The error code of the system fault that raised this exception.</param> public WinSysException(WinSysErrorCodes errorCode) : base( $"{typeof(WinSysErrorCodes).GetMemberAttribute<DisplayValueAttribute>(errorCode.ToString())}: {typeof(WinSysErrorCodes).GetMemberAttribute<DataValueAttribute>(errorCode.ToString())}" ) { this.addErrorData(errorCode); }
private void addErrorData(WinSysErrorCodes errorCode) { this.ErrorCode = errorCode; this.Data.Add("errorCode", errorCode); this.Data.Add("errorCodeInternalName", errorCode.ToString()); this.Data.Add("errorCodeValue", (short)errorCode); this.Data.Add( "errorCodeDisplayName", typeof(WinSysErrorCodes).GetMemberAttribute <DisplayValueAttribute>(errorCode.ToString())); this.Data.Add( "errorCodeData", typeof(WinSysErrorCodes).GetMemberAttribute <DataValueAttribute>(errorCode.ToString())); }
public static Exception GetSystemException(WinSysErrorCodes? systemErrorCode = null, string message = null) { var code = systemErrorCode == null ? GetLastErrorCode() : systemErrorCode.GetValueOrDefault(); var innerException = message == null ? new WinSysException(code) : new WinSysException(code, message); var exceptionInit = new object[] { "Exception caused by system error.", innerException }; var e = code.GenerateBoundException(exceptionInit); return e ?? innerException; }
/// <summary> /// Generates an exception from the <see cref="WinSysErrorCodes" /> <see cref="BoundExceptionTypeAttribute" /> /// information. /// </summary> /// <param name="code">The SysErrorCodes value from which to generate the bound exception.</param> /// <param name="exceptionInitParams">Initialization parameters for the bound exception.</param> /// <returns>An exception generated from the SysErrorCodes value.</returns> public static Exception GenerateBoundException(this WinSysErrorCodes code, params object[] exceptionInitParams) { // TODO Full implementation of BoundExceptionTypeAttribute.InitParamTypes list in SysErrorCodesExtensions.GenerateBoundException var boundExceptionAttribute = typeof(WinSysErrorCodes).GetMemberAttribute <BoundExceptionTypeAttribute>(code.ToString()); Exception boundException = null; var t = boundExceptionAttribute?.BoundExceptionType; if (t == null) { return(null); } var tConstructor = t.GetConstructor( BindingFlags.Public, null, boundExceptionAttribute.InitParamTypes, null); if (tConstructor != null) { try { boundException = tConstructor.Invoke(exceptionInitParams) as Exception; } catch (TypeInitializationException) { } } else { throw new MissingMethodException("The specified constructor did not exist."); } return(boundException); }
private void addErrorData(WinSysErrorCodes errorCode) { this.ErrorCode = errorCode; this.Data.Add("errorCode", errorCode); this.Data.Add("errorCodeInternalName", errorCode.ToString()); this.Data.Add("errorCodeValue", (short)errorCode); this.Data.Add( "errorCodeDisplayName", typeof(WinSysErrorCodes).GetMemberAttribute<DisplayValueAttribute>(errorCode.ToString())); this.Data.Add( "errorCodeData", typeof(WinSysErrorCodes).GetMemberAttribute<DataValueAttribute>(errorCode.ToString())); }
/// <summary> /// Creates a new WinSysException from the specified error code. The message is specified by message. /// The Inner Exception is also set; however, this may be considered redundant as the exception is inherently raised /// by a specific kernel fault. /// </summary> /// <param name="errorCode">The error code of the system fault that raised this exception.</param> /// <param name="message">The exception message.</param> /// <param name="innerException">The inner exception that caused this WinSysException to be thrown.</param> public WinSysException(WinSysErrorCodes errorCode, string message, Exception innerException) : base(message, innerException) { this.addErrorData(errorCode); }
/// <summary> /// Creates a new WinSysException from the specified error code. The message is automatically set to the SysErrorCode /// <see cref="DisplayValueAttribute">Display</see> and <see cref="DataValueAttribute">Data</see> /// attributes. /// </summary> /// <param name="errorCode">The error code of the system fault that raised this exception.</param> public WinSysException(WinSysErrorCodes errorCode) : base($"{typeof(WinSysErrorCodes).GetMemberAttribute<DisplayValueAttribute>(errorCode.ToString())}: {typeof(WinSysErrorCodes).GetMemberAttribute<DataValueAttribute>(errorCode.ToString())}") { this.addErrorData(errorCode); }