Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用自定义 HResult 或 errorCode 引发异常,所以我尝试了 ExternalException
throw new ExternalException("Login required", 0x6acfc5);
然而,当我捕捉到异常并查看它时HResult,我发现它不是0x6acfc5另一个奇怪的负数。
HResult
0x6acfc5
ExternalException("Login required", 0x6acfc5)
此构造函数接受 errorCode 作为第二个参数,它在 System.Int32
System.Int32
当您赋予 value 因为0x6acfc5它将转换为 int value7000005时,这就是您所看到的HResult
7000005
如果你打电话ex.HResult.ToString("X"),你会得到6ACFC5
ex.HResult.ToString("X")
6ACFC5
注意: ToString("X")将 int 值转换为十六进制字符串
ToString("X")