I m getting "The remote server returned an error: (403) Forbidden." error and want to catch this exception. I guess HttpException block should trap it as shown below but its not.
catch (HttpException wex)
{
if (wex.GetHttpCode().ToString() == "403")
//do stuff
}
I don't want to use generic exception block to catch this. What other exception could catch this?
See the attached the exception snapshotscreenshot.
It looks like the exception is being wrapped inside of another API-level exception object. You can conditionally catch the specific exception you are after and re-throw otherwise. Using this helper:
You can then use this catch block:
Take a look at the stacktrace without you catching it. If the code doesn't allow you to not catch it, and print it out to standard error stream. This will allow you to see the exception type and do your
try
block accordingly.