In my ASP.NET MVC 3 app, I have the following code:
try
{
return new ProxyResult(new Uri("http://example.org"));
}
catch (WebException)
{
}
However, when I try to access the page, I get a WebException (404 Not Found)… but the WebException should be caught. I don’t understand how this can possibly jump right out of my catch.
All you are putting in your
tryblock is a simple constructor call to theProxyResultwhich by the way is not some standard result => it’s probably something custom. The actual execution of the result (the invoke of theExecuteResult) method which might potentially throw the exception you are expecting happens much later and outside of your controller action. That’s the reason why no exception is throw in your controller action. You should put the try/catch inside the ExecuteResult method of this customProxyResultclass that you have written.