What do we need the PHP-exception code for? Any use case scenario?

The message is for display to the user, while the code is for use by your program. So for example, in your “database error” example, you might make up a set of codes like

  1. Can’t connect
  2. Error during query
  3. Empty result
  4. Error closing connection

and then use the appropriate code. Then when other parts of your code saw they exception, they would know what happened and could possibly deal with it intelligently.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)