public void LzaResultConstructor_Works(LzmaResult result, string expectedMessage) { var ex = new LzmaException(result); Assert.Equal(result, (LzmaResult)ex.HResult); Assert.Equal(expectedMessage, ex.Message); }
/// <summary> /// Throws a <see cref="LzmaException"/> if <see cref="LzmaResult"/> is not <see cref="LzmaResult.OK"/>. /// </summary> /// <param name="result"> /// The result value to check. /// </param> public static void ThrowOnError(LzmaResult result) { if (result != LzmaResult.OK) { throw new LzmaException(result); } }
private static Exception GetError(LzmaResult ret) { switch (ret) { case LzmaResult.MemError: return(new OutOfMemoryException("Memory allocation failed")); case LzmaResult.OptionsError: return(new ArgumentException("Specified preset is not supported")); case LzmaResult.UnsupportedCheck: return(new Exception("Specified integrity check is not supported")); case LzmaResult.DataError: return(new InvalidDataException("File size limits exceeded")); default: return(new Exception("Unknown error, possibly a bug: " + ret)); } }
private Exception ThrowError(LzmaResult ret) { NativeMethods.lzma_end(ref this.lzmaStream); return(GetError(ret)); }
private static string GetDescription(LzmaResult result) => result switch {
/// <summary> /// Initializes a new instance of the <see cref="LzmaException"/> class, based on an <see cref="LzmaResult"/> /// error code. /// </summary> /// <param name="result"> /// A message which describes the error. /// </param> public LzmaException(LzmaResult result) : base(GetDescription(result)) { this.HResult = (int)result; }