class XWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri Url)
{
var Request = base.GetWebRequest(Url);
...........
return Request;
}
}
Using:
try
{
XWebClient Client = new XWebClient();
Client.DownloadString(new Uri("badurl:100500"));
}
catch
{
MessageBox.Show("exception");
}
I was hoping to get a messagebox, but I get an unhandled exception. What am I doing wrong?
Exception: System.NotSupportedexception
Message: The URI prefix is not recognized
Trace:
System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
System.Net.WebRequest.Create(Uri requestUri)
System.Net.WebClient.GetWebRequest(Uri address)
XWebClient.GetWebRequest(Uri Url) в [path]\XWebClient.cs:строка 28
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
It sounds to me like you are running it under the debugger with "break on all managed exceptions" enabled. If that is the case the debugger would break on the line that threw the exception before the handler runs. Your handler is still working, the debugger is just letting you inspect the error beforehand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With