SALES: 1-800-867-1380
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Exception Handling Overview (Windows Server AppFabric Caching)

The caching API of Windows Server AppFabric throws .NET exceptions when errors occur. This topic reviews basic error handling concepts and provides an example.

The DataCacheException Class

A common DataCacheException object is thrown for errors that are specific to the AppFabric caching methods. The DataCacheException object contains four properties that can help you diagnose the cause of the exception:


DataCacheException property Description


A string that describes the error.


An integer value that corresponds to an error code constant in the DataCacheErrorCode class.


An integer value that corresponds to a sub-status constant in the DataCacheErrorSubStatus class.


An exception instance that caused the current exception. This value can be null.

Some failures, such as a timeout, can occur from any cache client method. Your application code should be prepared to handle these common exceptions. For more information, see Common Exceptions (Windows Server AppFabric Caching).

Some failures do not throw an exception. For example, the Get method returns a null value if the key is not found. Other methods can return Boolean values to indicate success or failure. For more information about specific methods, see the Microsoft.ApplicationServer.Caching namespace in the Windows Server AppFabric Class Library documentation.


The following example attempts to put a string object named strObject into a DataCache named myCache. The overloaded Put method is used to specify a cache region for the object. If this region does not yet exist in the cache, a DataCacheException object is thrown with an error code of RegionDoesNotExist. In this example, this error is handled by creating the region and retrying the put operation.

string strKey = "key0";
string strObject = "Source String";

   // Put a string object into the cache region, "Region1"
   myCache.Put(strKey, strObject, "Region1");
catch (DataCacheException cacheError)
   // Look at the ErrorCode property to see if the Region is missing
   if (cacheError.ErrorCode == DataCacheErrorCode.RegionDoesNotExist)
      // Create the Region and retry the Put call
      myCache.Put(strKey, strObject, "Region1");

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft