• 关于异常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:
    onexist.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);
    }
  • 相关阅读:
    设计模式之三:Abstract Factory(转)
    设计模式之二:adapter模式(转)
    设计模式之一:设计原则(转)
    双链表操作
    单链表操作
    C#-Activex插件操作指南
    积分源码上线
    換友情鏈接
    企业短信群发
    掉了,全掉了。
  • 原文地址:https://www.cnblogs.com/yilang/p/13225001.html
Copyright © 2020-2023  润新知