Witam.
W jaki sposób wyłapać wyjątek UriFormatException?
UriFormatException was unhandled
Invalid URI: The format of the URI could not be determined.
przy linijce:
HttpWebRequest www = (HttpWebRequest)HttpWebRequest.Create(page);
To mój pierwszy raz z wyjątkiem, na początku próbowałem zwykłą instrukcją warunkową, jednak nie pomogło.
Próbowałem różnie, np.
try{
HttpWebRequest www= (HttpWebRequest)HttpWebRequest.Create(page);
}
catch(UriFormatException exc){
MessageBox.Show("bum parapapa");
}
Jednak wywalało:
Error 1 The name 'www' does not exist in the current context
przy dalszej części kodu.
Cały kod:
string url = textBox1.Text;
string page = @url;
HttpWebRequest www = (HttpWebRequest)HttpWebRequest.Create(page);
StreamReader SR = new StreamReader(www.GetResponse().GetResponseStream());
Char[] buf = new Char[256];
int licz = SR.Read(buf, 0, 256);
while (licz > 0)
{
String tytul = new String(buf, 0, licz);
Match match = Regex.Match(tytul, @"<title>([^<]+)", RegexOptions.IgnoreCase);
if (match.Success)
{
string asd = match.Groups[1].Value;
listBox1.Items.Add(asd);
}
licz = SR.Read(buf, 0, 256);
}
textBox1.Clear();