On-machine error compensation (OMEC) is efficient at improving machining accuracy without increasing extra manufacturing cost, and involves the on-machine measurement (OMM) of machining accuracy and modification of program code based on the measurement results. As an excellent OMM technique, chromatic confocal sensing allows for the rapid development of accurate and reliable error compensation technique. The present study integrated a non-contact chromatic confocal probe into an ultra-precision machine for OMM and OMEC of machined components. First, the configuration and effectiveness of the OMM system were briefly described, and the relevant OMEC method was presented. With the OMM result, error compensation software was then developed to automatically generate a modified program code for error compensation. Finally, a series of cutting experiments were performed to verify the validity of the proposed OMEC method. The experimental results demonstrate that the proposed error compensation method is reliable and considerably improves the form error of machined components.