📜 ⬆️ ⬇️

When a critical mistake brings joy ...

After reading recently on drunken head " Handling errors and exceptions in PHP ", I decided to apply this knowledge in practice. Honestly, 6 hours ago I didn’t know where it would lead me, but as a result, now my scripts light up such a simpot screen when there is an error:




To be honest, PHP here as such is not much. Create your own subclass Exception ; With set_error_handler order PHP to throw our new exception whenever an error or warning occurs; and wrap all our code in try { … } catch () { … } . In short, everything is as in the above article. Most of the time, I spent on formatting styles and images (which, by the way, are inserted using url-data; that is, my class turned out to be independent of external resources).
')

“Where is the code, balabolka?”



All the necessary code is concentrated in a single file , which is part of the future framework ( NB! ... in its infancy ;-)). Before you insert this file into your project, you need to perform the following operations with it:

  1. Get rid of the "jammer" in the first line;
  2. All references to Aero()->get_option(...) replace the second parameter of the called method. (For example, Aero()->get_option('catch_errors', E_ALL, 'error_handler') turns into just E_ALL .)

Source: https://habr.com/ru/post/30829/


All Articles