CUserException

CObject
 └CException
   └CUserException

抛出一个CUserException来停止一个结束-用户操作。当你想要对应用程序指定的异常使用抛出/捕获异常机制时,可以使用CUserException。在类名中的“User”可以解释为“我的用户做了某些我不想处理的异常事情”。
在调用全局函数AfxMessageBox之后,通常会抛出一个CUserException来通知用户操作失败了。当你编写一个异常处理程序时,由于用户已经获得了失败的通知,所以你要特别处理这个异常。在某些情况下,框架会抛出这个异常。你可以自己抛出一个CUserException,以警告用户,然后调用全局函数AfxThrowUserException。
在下面的示例中,一个函数包含的操作可能会失败,警告用户并抛出一个CUserException。调用函数捕获这个异常并特别处理它:
void DoSomeOperation( )
{
  // 如果出错则处理
  AfxMessageBox( "The x operation failed" );
  AfxThrowUserException( );
}

BOOL TrySomething( )
{
  TRY
  {
    // Could throw a CUserException or other exception.
    DoSomeOperation( );
  }
  CATCH( CUserException, e )
  {
    return FALSE; // User already notified.
  }
  AND_CATCH( CException, e )
  {
    // For other exception types, notify user here.
    AfxMessageBox( "Some operation failed" );
    return FALSE;
  }
  END_CATCH
  return TRUE; // No exception thrown.
}
有关使用CUserException的更多信息,参见“Visual C++程序员指南”中的“异常”。

#include <afxwin.h>

请参阅:
CException, AfxMessageBox, AfxThrowUserException