Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try-catch not working

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)
like image 745
user2058005 Avatar asked Jun 10 '26 21:06

user2058005


1 Answers

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.

like image 73
Ed S. Avatar answered Jun 12 '26 11:06

Ed S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!