다음을 통해 공유


CUserException 클래스

최종 사용자 작업을 중지하도록 throw됩니다.

구문

class CUserException : public CSimpleException

설명

애플리케이션별 예외에 throw/catch 예외 메커니즘을 사용하려는 경우에 사용합니다 CUserException . 클래스 이름의 "User"는 "내 사용자가 처리해야 하는 예외적인 작업을 했습니다."로 해석될 수 있습니다.

CUserException A는 일반적으로 전역 함수 AfxMessageBox 를 호출하여 사용자에게 작업이 실패했음을 알리기 위해 throw됩니다. 예외 처리기를 작성할 때는 일반적으로 사용자에게 오류 알림이 이미 제공되었으므로 예외를 특별히 처리합니다. 프레임워크는 경우에 따라 이 예외를 throw합니다. 자신을 throw CUserException 하려면 사용자에게 경고한 다음 전역 함수 AfxThrowUserException를 호출합니다.

아래 예제에서는 실패할 수 있는 작업을 포함하는 함수가 사용자에게 경고하고 throw합니다 CUserException. 호출 함수는 예외를 catch하고 특별히 처리합니다.

void DoSomeOperation()
{
   // Processing
   // If something goes wrong...
   AfxMessageBox(_T("The x operation failed"));
   AfxThrowUserException();
}

BOOL TrySomething()
{
   try
   {
      // Could throw a CUserException or other exception.
      DoSomeOperation();
   }
   catch (CUserException* pe)
   {
      pe->Delete();
      return FALSE;    // User already notified.
   }
   catch (CException* pe)
   {
      // For other exception types, notify user here.
      pe->ReportError();
      return FALSE;
   }
   return TRUE;   // No exception thrown.
}

사용에 CUserException대한 자세한 내용은 MFC(예외 처리) 문서를 참조하세요.

상속 계층 구조

CObject

CException

CSimpleException

CUserException

요구 사항

헤더: afxwin.h

참고 항목

계층 구조 차트
CException 클래스