Question: when to use notwithstanding the foregoing?
Answer: “Notwithstanding the foregoing” means “in spite of the things previously mentioned or written.”
“Notwithstanding anything to the contrary” is legal language that declares that a clause supersedes anything forthcoming that might contradict it.