关于异常System.ComponentModel.Win32Exception


什么是Win32Exception

就是封装了Win32 Error Code的异常。也就是GetLastError返回的值。Win32错误代码在显示时从其数字表示形式转换为系统消息。使用NativeErrorCode访问与此异常关联的错误代码的数字表示形式

继承关系

Object
Exception
SystemException
ExternalException
Win32Exception

有如下子类

System.Net.HttpListenerException
System.Net.NetworkInformation.NetworkInformationException
System.Net.Sockets.SocketException
System.Net.WebSockets.WebSocketException

 

HRESULT

80004005

 

下面的代码示例演示如何捕获Win32异常并解释其内容。该示例尝试启动不存在的可执行文件,这将导致Win32异常。在捕捉到异常时,该示例获取相应的错误消息、代码和异常的来源。

try {
System.Diagnostics.Process myProc = new System.Diagnostics.Process();
myProc.StartInfo.FileName = "c:\nonexist.exe";  //Attempting to start a non-existing executable
myProc.Start();    //Start the application and assign it to the process component.    
}
catch(Win32Exception w) {
Console.WriteLine(w.Message);
Console.WriteLine(w.ErrorCode.ToString());
Console.WriteLine(w.NativeErrorCode.ToString());
Console.WriteLine(w.StackTrace);
Console.WriteLine(w.Source);
Exception e=w.GetBaseException();
Console.WriteLine(e.Message);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM