我正在使用这种方法: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);
}
但这似乎非常草率-肯定有更好的方法吗?