def catchLogByHour(..., errorHandler): while ....: if hasError: errorHandler(...) def error1(...): .... catchLogByHour(...,error1) def error2(...): .... catchLogByHour(...,error2) def error#(...): .... catchLogByHour(...,error2)