If an employer or other person is prosecuted for non-compliance with a particular statutory duty, and a code of practice governing compliance with the relevant duty was in force at the time of the alleged non-compliance, it is a defence to the charge to establish that the defendant complied with the code of practice in relevant respects.