Well, it is not that wrong if we think so. But ,actually, they are different.
中文, Chinese, is the languages used by people from China. There are so many dialects, both spoken and written, in China. Several most used are Mandarin Chinese,Cantonese, Hokkin.
汉语 is the language used by the mojority people in China--- Han People. 普通话,Mandarin Chinese, the only official language in China, is based on 汉语. So practically, we take Mandarin Chinese as 汉语。
Most of the foreigner learners learn the official language---Mandarin Chinese. They would think that is the language used in China, so it is logically 中文。
Some overseas Chinese prefer to call the language 华文。Personally, I think this is acceptable. It is the language of a race, not only a country.