It is not a "foul" because no one is offside (so a penalty would not be awared), however, you would lose possession because it is a knock-on or forward pass (play advantage to other side, or stop play for a scrum).
If you've deliberately thrown it forwards, that's a penalty I believe. You can accidentally pass forwards, or knock on, but I suspect throwing it forwards on purpose is a penalty.
If it's not a penalty, then at the very least, as above, it's a knockon/forwards pass, and therefore a scrum from where you were when you threw the ball.