Fix IDE0025 (use expression body for properties)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / Runtime / InteropServices / ExternalException.cs
blobf04fa6fd5c0da23472638ebbf23f4dd916e4cc3a
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 // See the LICENSE file in the project root for more information.
5 /*=============================================================================
6 **
7 **
8 **
9 ** Purpose: Exception base class for all errors from Interop or Structured
10 ** Exception Handling code.
13 =============================================================================*/
15 using System.Globalization;
16 using System.Runtime.Serialization;
18 namespace System.Runtime.InteropServices
20 // Base exception for COM Interop errors &; Structured Exception Handler
21 // exceptions.
22 [Serializable]
23 [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
24 public class ExternalException : SystemException
26 public ExternalException()
27 : base(SR.Arg_ExternalException)
29 HResult = HResults.E_FAIL;
32 public ExternalException(string? message)
33 : base(message)
35 HResult = HResults.E_FAIL;
38 public ExternalException(string? message, Exception? inner)
39 : base(message, inner)
41 HResult = HResults.E_FAIL;
44 public ExternalException(string? message, int errorCode)
45 : base(message)
47 HResult = errorCode;
50 protected ExternalException(SerializationInfo info, StreamingContext context)
51 : base(info, context)
55 public virtual int ErrorCode => HResult;
57 public override string ToString()
59 string message = Message;
60 string className = GetType().ToString();
62 string s = className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")";
64 if (!string.IsNullOrEmpty(message))
66 s = s + ": " + message;
69 Exception? innerException = InnerException;
70 if (innerException != null)
72 s = s + Environment.NewLine + InnerExceptionPrefix + innerException.ToString();
75 if (StackTrace != null)
76 s += Environment.NewLine + StackTrace;
78 return s;