如何知道Windows store应用程序类型可能抛出什么类型的异常

本文关键字:类型 什么 异常 何知道 Windows store 应用程序 | 更新日期: 2023-09-27 17:52:34

我使用这个方法:DatagramSocket.BindEndpointAsync()

我怎么知道它可能抛出什么类型的异常??这个官方示例显示了捕获所有异常,如下所示:

        // Start listen operation. 
        try 
        { 
            await listener.BindServiceNameAsync(ServiceNameForListener.Text); 
            rootPage.NotifyUser("Listening", NotifyType.StatusMessage); 
        } 
        catch (Exception exception) 
        { 
            CoreApplication.Properties.Remove("listener"); 
            // If this is an unknown status it means that the error is fatal and retry will likely fail. 
            if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown) 
            { 
                throw; 
            } 
            rootPage.NotifyUser("Start listening failed with error: " + exception.Message, NotifyType.ErrorMessage); 
        } 

但这看起来非常草率——肯定有更好的方法吗?

如何知道Windows store应用程序类型可能抛出什么类型的异常

c#不要求开发人员用可以抛出的异常列表标记每个方法(Java有这个要求)。这就是为什么你必须依靠文档或检查源代码来解决问题。

Async/Await在这种情况下不会改变任何东西