If the distance from the start or the end point of the curve to another curve is lower than a threshold, I want to draw a new line and join with the previous one. Like this:
You can easily solve it using CURVE PROXIMITY component. There you can also check the distance between two curves apart from getting the closest point between both curves.