Get rid of TRY and CATCH in each command message handling function

zhaozj2021-02-08  209

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}

转载请注明原文地址:https://www.9cbs.com/read-1856.html

New Post(0)