img/mfc2.jpg

CUserException - przykład


void DoSomeOperation( )
{
      // Processing
      // If something goes wrong...
      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.
}