Make your own free website on

CModbusException Class

class CModbusException : public CException

A CModbusException object represents an exception condition related to a communication operation whith modbus slave device. These exceptions include communications exceptions and modbus functions exceptions, for instance , if you try to preset a register and the address is invalid, the modbus slave return a message indicating this invalid operation.

You do not need to create objects of this class, this creation is intended to be made inside CModbus Class.


CModbusException(CString& sMessage,int nError);


sMessage - String with error Description.

nError - Error number.



extern CModbus* pModbus; // this pointer is created by a derived class.


try {

//It's not needed to verify each call for errors

pModbus->ForceSingleCoil(17,172,TRUE) ; //force coil 173 ON in slave device 17
pModbus->PresetSingleRegister(17,1,3) ; //preset register 40002 to 03 in slave device 17


catch(CModbusException* pException) {

TCHAR szCause[255];

CString strFormatted;

pException->GetErrorMessage(szCause, 255);
strFormatted = _T("Modbus Function Error-");

strFormatted += szCause; AfxMessageBox(strFormatted);





See also: CException in MCF library help files.