<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def error(self, msg='Program error: {err}', exit=None):
 """ Error handler factory This function takes a message with optional ``{err}`` placeholder and returns a function that takes an exception object, prints the error message to STDERR and optionally quits. If no message is supplied (e.g., passing ``None`` or ``False`` or empty string), then nothing is output to STDERR. The ``exit`` argument can be set to a non-zero value, in which case the program quits after printing the message using its value as return value of the program. The returned function can be used with the ``progress()`` context manager as error handler. """

        def handler(exc):
            if msg:
                self.perr(msg.format(err=exc))
            if exit is not None:
                self.quit(exit)
        return handler