It is haram to swear by anything other than Allah. The Prophet (peace and blessings be upon him) said: “Whoever swears an oath then let him swear by Allah or else keep silent.” (Agreed upon hadith) And he also said: “Whoever swears, let him not swear by anything other than Allah.” (Reported by an-Nasa’i)
However, if one swears by anything other than Allah, then he is not regarded a disbeliever or outside the pale of Islam, though he has committed a sin of which he should repent and seek Allah’s forgiveness.
Answering the question in point, the erudite Muslim scholar of Bahrain, Sheikh Nizam Ya`qubi, states:
“The Prophet (peace and blessings be upon him) said, “Whosoever swears by other than Allah, then they have committed shirk (associated other deities with Allah).” This means that we are not allowed to swear by other than Allah, His Names, and Glorified Attributes. However, if somebody swears by other than Allah, their Islam is not nullified, but they have sinned. They should repent for this act and not return to it ever again.
If you do not mean it and it is just a matter of word of mouth without intention, then you are excused. Allah said, “Allah will not take you to task for that which is unintentional in your oaths, but He will take you to task for the oaths which ye swear in earnest. The expiation thereof is the feeding of ten of the needy with the average of that wherewith ye feed your own folk, or the clothing of them, or the liberation of a slave, and for him who findeth not (the wherewithal to do so) then a three days’ fast. This is the expiation of your oaths when ye have sworn; and keep your oaths. Thus Allah expoundeth unto you His revelations in order that ye may give thanks.” (Al-Ma’idah :89)”
Here, we’d like to add that Allah has forgiven us what we have done by mistake, out of forgetfulness or under duress. A sleepy person who is unconscious of what he is saying or doing is not held accountable for this. The Prophet (peace and blessings be upon him) said: “The pen is raised for three groups [of people] that is, they will not be responsible for their actions: the insane until they become sane, those who are sleeping until they awaken, and the young until they reach puberty.” (Reported by Ahmad, Abu Dawud, and at-Tirmidhi) Finally, what one only thinks of but does not utter or act accordingly is also forgiven. The Prophet (peace and blessings be upon him) said, “Allah has forgiven my Ummah of the whisperings of their souls so long as they do not talk about it, or act accordingly.”