| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.ComponentModel; |
| | | 5 | | using System.Runtime.Serialization; |
| | | 6 | | |
| | | 7 | | namespace System.IO.Compression |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// This is the exception that is thrown when a ZLib returns an error code indicating an unrecoverable error. |
| | | 11 | | /// </summary> |
| | | 12 | | [Serializable] |
| | | 13 | | [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 |
| | | 14 | | public class ZLibException : IOException, ISerializable |
| | | 15 | | { |
| | 0 | 16 | | private readonly string? _zlibErrorContext = string.Empty; |
| | 0 | 17 | | private readonly string? _zlibErrorMessage = string.Empty; |
| | 0 | 18 | | private readonly ZLibNative.ErrorCode _zlibErrorCode = ZLibNative.ErrorCode.Ok; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// This is the preferred constructor to use. |
| | | 22 | | /// The other constructors are provided for compliance to Fx design guidelines. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="message">A (localised) human readable error description.</param> |
| | | 25 | | /// <param name="zlibErrorContext">A description of the context within zlib where the error occurred (e.g. the f |
| | | 26 | | /// <param name="zlibErrorCode">The error code returned by a ZLib function that caused this exception.</param> |
| | | 27 | | /// <param name="zlibErrorMessage">The string provided by ZLib as error information (unlocalised).</param> |
| | 0 | 28 | | public ZLibException(string? message, string? zlibErrorContext, int zlibErrorCode, string? zlibErrorMessage) : b |
| | 0 | 29 | | { |
| | 0 | 30 | | _zlibErrorContext = zlibErrorContext; |
| | 0 | 31 | | _zlibErrorCode = (ZLibNative.ErrorCode)zlibErrorCode; |
| | 0 | 32 | | _zlibErrorMessage = zlibErrorMessage; |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// This constructor is provided in compliance with common .NET Framework design patterns; |
| | | 37 | | /// developers should prefer using the constructor |
| | | 38 | | /// <code>public ZLibException(string message, string zlibErrorContext, ZLibNative.ErrorCode zlibErrorCode, stri |
| | | 39 | | /// </summary> |
| | 0 | 40 | | public ZLibException() { } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// This constructor is provided in compliance with common .NET Framework design patterns; |
| | | 44 | | /// developers should prefer using the constructor |
| | | 45 | | /// <code>public ZLibException(string message, string zlibErrorContext, ZLibNative.ErrorCode zlibErrorCode, stri |
| | | 46 | | /// </summary> |
| | | 47 | | /// <param name="message">The error message that explains the reason for the exception.</param> |
| | | 48 | | /// <param name="innerException">The exception that is the cause of the current exception, or a <code>null</code |
| | 0 | 49 | | public ZLibException(string? message, Exception? innerException) : base(message, innerException) { } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Initializes a new ZLibException with serialized data. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thr |
| | | 55 | | /// <param name="context">The StreamingContext that contains contextual information about the source or destinat |
| | | 56 | | [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma |
| | | 57 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 58 | | protected ZLibException(SerializationInfo info, StreamingContext context) : base(info, context) |
| | 0 | 59 | | { |
| | 0 | 60 | | _zlibErrorContext = info.GetString("zlibErrorContext"); |
| | 0 | 61 | | _zlibErrorCode = (ZLibNative.ErrorCode)info.GetInt32("zlibErrorCode"); |
| | 0 | 62 | | _zlibErrorMessage = info.GetString("zlibErrorMessage"); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma |
| | | 66 | | void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context) |
| | 0 | 67 | | { |
| | 0 | 68 | | base.GetObjectData(si, context); |
| | 0 | 69 | | si.AddValue("zlibErrorContext", _zlibErrorContext); |
| | 0 | 70 | | si.AddValue("zlibErrorCode", (int)_zlibErrorCode); |
| | 0 | 71 | | si.AddValue("zlibErrorMessage", _zlibErrorMessage); |
| | 0 | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |