Each command process can cause an exception, and throw an exception usually leads to the termination of the current command processing. Writing an exception processing code during each command process is a very cumbersome work. Since the command is processed in ccmdtarget :: oncmdmsg, you can process all command processing processes generated in this function without having to write an exception handler.
CcccxCommandHandler is a class based on CCMDTARGET. This example can be extended to all CCMDTARGET derived classes.
BOOL CCccXCommandHandler :: OnCmdMsg (UINT nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo) {BOOL bRet = TRUE; TRY {bRet = CCmdTarget :: OnCmdMsg (nID, nCode, pExtra, pHandlerInfo);} CATCH (COleDispatchException, pEx ) {CGLOBAL :: ProcessoLeDispatChexception (PEX);} and_catch (CEXCEPTION, PEX) {cglobal :: processException (pex);} end_catch return}