You can cancel the creation of a line or polygon whose creation you have not completed yet.
Procedure
Press the Esc key.
Existing segments are deleted. This also applies to other graphic objects if you create them with the mouse button pressed in order to select the size of the graphic object.
You can also click the right mouse button.