Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Catching a WebException
    primarykey
    data
    text
    <h2>The Problem</h2> <p>We are occasionally getting a WebException that, as hard as we try we can not seem to catch. This results in an error showing up in the event log on the WebServer.</p> <h2>Details</h2> <p>We have an ASP.Net application that uses several webservices. One of the webservice methods can take a long time to run. To address this we use caching. When the cache times out, we use the callback featue of ASP.Net Cacheing (CacheItemRemovedCallback) to recall the webservice and repopulate the cache. See code example below</p> <p>Our problems starts when, occasionally, the <em>webservice</em> times out. When this happens it throws a WebException. We put a Try/Catch block round our code, and just catch and log exceptions. However, for some reason, this does not seem to catch the WebException and I can not work out why. </p> <p>I have seen some weird behavior in the past with ThreadAbort exceptions not getting caught as expected. I wonder if this could be related? Also, another thing we do is create a new HTTPContext in order to access the Cache. This works fine, and is needed because the callback is not in the main Request thread. I wonder if this could also be related</p> <p>Any advice welcome!</p> <p>Cheers James</p> <h2>Code Example</h2> <p>Public Shared Sub CacheCallbackMethod()</p> <pre><code>Try If HttpContext.Current Is Nothing Then HttpContext.Current = New HttpContext(New Hosting.SimpleWorkerRequest(String.Empty, String.Empty, New System.IO.StringWriter())) End If [Code to fetch data] Cache.Insert(key, obj, Nothing, Nothing, SlidingExpTimeSpan, Priority, CallbackMethod) Catch ex As Exception End Try </code></pre> <p>End Function</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload