Let's check what the Bible has to say about this.
Genesis 38:9-10
- But Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to keep from providing offspring for his brother.
- What he did was wicked in the LORD’s sight; so the LORD put him to death also.