cancel house contract before closing

If you decide to buy a house and change your mind just before closing can you get out of your home purchase contract? It depends.