"Crocodile tears" are an oft-quoted turn of phrase but humans are the only animals known to cry as a form of emotional release. (While crocs do indeed shed tears, they are a physiological – not grief-stricken – response.) We cry when we're sad, but we also cry when we're happy and when we're angry. Why is this?
First thing's first. There are three different types of tears. The first, basal tears, are produced by the tear ducts on a near constant basis but at such a slow pace that you won't even notice. These exist to lubricate, nourish, clean, and protect the cornea, aka keep the eye healthy. You can think of them as a shield, creating a barrier between your peepers and the dirt and debris of the outside world. The second are reflex tears, which instinctively appear when your eye is irritated, whether that irritation is caused by smoke particles or a fallen eyelash or something else. Not only do these tears help wash away the thing causing the irritation, but they also contain extra antibodies to kill any bacteria that may be contaminating the eye.
The final and third type is the most interesting. Emotional (or psychic) tears are triggered by exceptionally strong feelings, both positive (joy and excitement, for example) and negative (sadness, anger, and fear etcetera). Experts aren't exactly sure why humans have evolved to express our emotions via the medium of salty eye water. However, there are a few potential explanations.
One popular theory is that emotional tears are a form of non-verbal communication. A baby, for example, might not be able to speak to express its hunger or loneliness, but it can evoke a strong and immediate reaction from its mom (or dad) when it cries. In adulthood, it might be a way to openly display feelings of vulnerability or joy to build connections with friends, family, and acquaintances. Or, alternatively, spark an empathetic response from those around you (provided they're not psychopaths) when you're emotionally or physically in trouble. In fact, tears are such a powerful social signal that even our pets know how to respond as soon as we start blubbering.
Another reason could be that welling up offers some kind of release for physical and emotional pain. All tears constitute some mix of water, salt, oil, and germ-killing enzymes but those that stream down our faces when we're emotional or in pain contain higher levels of various stress hormones and feel-good chemicals, including one called leucine enkephalin, which is an endorphin and natural painkiller. This pleasing combination of oxytocin and endorphins could explain the concept of a "good cry".
One hypothesis that is probably safe to rule out is the idea that modern humans descended from aquatic apes, with salty tears being now-useless evolutionary byproducts that once allowed these "ancestors" of ours to live and prosper in salty water. (For the record, we do not descend from aquatic apes.)
But while the cause of emotional tears may be something of a conundrum, their mechanism is much better understood. All tears are produced by the lacrimal glands, found above each eye. With basal tears, blinking causes the liquid to spread across the surface of the eye. Leftover tears then drain through the puncta (holes in the corners of the upper and lower eyelids), through the canaliculus, and down the tear duct, where they empty through your nostrils. Because we only produce one-fifth or so of basal tears per day, the system works pretty efficiently.
However, when we are upset or otherwise emotional, we can produce half a cup (or more) of tears in just minutes. This essentially overloads the system so that instead of draining through the puncta, tears roll down our cheeks. It is also why crying can make our nose run.
As for why some people are known to cry over ads (guilty) while others can't shed a tear at their grandmother's funeral, there's another mystery. Though gender, culture, and personality are all likely factors.