There are several ways to end a Mathematica session. If you are using Mathematica interactively, typing Exit[ ] or Quit[ ] on an input line will always terminate Mathematica.
If you are taking input for Mathematica from a file, Mathematica will exit when it reaches the end of the file. If you are using Mathematica interactively, it will still exit if it receives an end-of-file character (typically d). You can stop Mathematica from doing this by setting $IgnoreEOF=True.