We read in Saheeh Bukhari, Vol. 2, Book 18, Hadith 158:
Narrated Abu Bakra:
Allah's Messenger said: "The sun and the moon are two signs amongst the signs of Allah and they do not eclipse because of the death of someone but Allah frightens His devotees with them."
This opposes science. We know that this is not the purpose of eclipses.
One needs to differentiate between the scientific and Shari' reasons for eclipses. Reading the below three links would help one grasp this better:
IslamicAwakening.Com: Understanding Eclipses the Islamic way
Eclipses should inspire fear in a believer's heart | IslamToday - English
Islam Question and Answer - If an eclipse is a natural phenomenon, then why should we feel scared and pray?