[英]NUnit and NSubstitute fail to properly catch exception in unittest
[英]Catch internet connection fail exception in button click
當電話應用程序上沒有互聯網時,如何捕獲webclient的嘗試,因為它會返回未處理的異常並關閉該應用程序。
您必須在實際的Windows Phone設備中測試網絡連接,因為Windows Phone仿真器始終會返回Networkavailable true(即使未連接到Internet)。
首先檢查網絡(如果可用),然后執行所需的操作,否則將獲得用戶友好的消息:
if (NetworkInterface.GetIsNetworkAvailable() == true)
{
//do something which you want
}
else
{
MessageBox.Show( "Network is not Available.");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.