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 /*=============================================================================
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
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
)
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
)
50 protected ExternalException(SerializationInfo info
, StreamingContext 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
;