예외 처리 개요(Windows Server AppFabric 캐싱)

오류가 발생하면 Windows Server AppFabric의 캐싱 API에서 .NET 예외가 발생합니다. 이 항목에서는 기본 오류 처리 개념을 검토하고 예제를 제공합니다.

DataCacheException 클래스

AppFabric 캐싱 메서드에 관련된 오류의 경우 일반적인 DataCacheException 개체가 발생합니다. DataCacheException 개체에는 예외의 원인 진단을 지원할 수 있는 4개 속성이 포함됩니다.

DataCacheException 속성 설명

Message

오류를 설명하는 문자열.

ErrorCode

DataCacheErrorCode 클래스에서 오류 코드 상수에 해당하는 정수 값.

SubStatus

DataCacheErrorSubStatus 클래스에서 하위 상태 상수에 해당하는 정수 값.

InnerException

현재 예외를 발생시키는 예외 인스턴스. 이 값은 null이 될 수 있습니다.

캐시 클라이언트 메서드에서 시간 제한 같은 몇 가지 오류가 발생할 수 있습니다. 이러한 일반적인 예외를 처리하도록 응용 프로그램 코드를 준비해야 합니다. 자세한 내용은 공통 예외(Windows Server AppFabric 캐싱)를 참조하십시오.

참고

몇몇 오류에서는 예외가 발생하지 않습니다. 예를 들어, Get 메서드는 키를 찾을 수 없는 경우 null 값을 반환합니다. 다른 메서드는 성공 또는 실패를 나타내기 위해 부울 값을 반환할 수 있습니다. 특정 메서드에 대한 자세한 내용은 Windows Server AppFabric 클래스 라이브러리 문서에서 Microsoft.ApplicationServer.Caching 네임스페이스를 참조하십시오.

예제

다음 예제에서는 strObject(이)라는 문자열 개체를 myCache라는 DataCache에 삽입합니다. 오버로드된 Put 메서드를 사용하여 개체에 대한 캐시 영역을 지정합니다. 캐시에 이 영역이 없는 경우 DataCacheException 개체가 RegionDoesNotExist 오류 코드와 함께 발생합니다. 이 예제에서 이 오류는 영역을 만들고 put 작업을 다시 시도하여 처리합니다.

Dim strKey As String = "key0"
Dim strObject As String = "Source String"

Try
   ' Put a string object into the cache region, "Region1"
   myCache.Put(strKey, strObject, "Region1")

Catch cacheError As DataCacheException
   ' Look at the ErrorCode property to see if the Region is missing
   If (cacheError.ErrorCode = DataCacheErrorCode.RegionDoesNotExist) Then

      ' Create the Region and retry the Put call
      myCache.CreateRegion("Region1")
      myCache.Put(strKey, strObject, "Region1")
   End If
End Try
string strKey = "key0";
string strObject = "Source String";

try
{
   // 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.CreateRegion("Region1");
      myCache.Put(strKey, strObject, "Region1");
   }
}

참고 항목

개념

공통 예외(Windows Server AppFabric 캐싱)
캐시 클라이언트 시간 제한 구성(Windows Server AppFabric 캐싱)

  2011-12-05