It's currently hard to catch exceptions raised during processing a Modbus request in a subclass of RequestHandler.process() because RequestHandler.process() catches all exceptions.
It would be better to create a method RequestHandler.process_exceptions which takes the exception and the request ADU and returns the reponse ADU.
RequestHandler(BaseRequestHandler):
def handle(self):
try:
req_adu = socket.recv()
resp_adu = self.process(req_adu)
except Exception as e:
resp_adu = self.process_exception(e, req_adu)
self.respond(resp_adu)
def process_exception(self, e, req_adu):
""" Based on error occured return correct response ADU. """
pass
It's currently hard to catch exceptions raised during processing a Modbus request in a subclass of
RequestHandler.process()
becauseRequestHandler.process()
catches all exceptions.It would be better to create a method
RequestHandler.process_exceptions
which takes the exception and the request ADU and returns the reponse ADU.