Which method is "better"?
It depends on your needs. This is not to say which one is better (and there are other ways to handle errors, and you should also consider when you really want to discuss error handling, for which this site is probably not suitable).
Any advantage of throwing an exception instead of stopping script execution?
An exception can be caught, but die cannot be caught. If you want to test your code, for example, die are often a show stopper.
In addition, an exception may contain more information and carry it more accurately. A message, for example, is more accessible with an exception than with die . The exception stores the file and the line in which it was selected. For debugging, there is a stack trace, etc.
hakre source share