I am learning to code since a few months. Today I want to code a password manager. Everything works fine but the get icon function has problem if a host is unreachable. This function is to get the favicon from the webpage.
Try
For Each myItem As ListViewItem In lv_data.Items
Dim baseurl = myItem.Text
Dim url As Uri = New Uri(baseurl)
If url.HostNameType = UriHostNameType.Dns Then
Dim iconURL = "http://" & url.Host & "/favicon.ico"
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim stream As System.IO.Stream = response.GetResponseStream()
imglist.Images.Add(Image.FromStream(stream))
lv_data.Items.Item(myItem.Index).ImageIndex = myItem.Index
End If
Next
Catch ex As WebException
End Try
Some servers respond with a Exception :
Remote host could not be resolved
. When that happens the whole for each loop stops. I am looking for a way to ignore that error and proceed with the next item from the listview.
Can anybody give me a tip or maybe a solution.
Best regards, Der King