關於異常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