Tuesday 25 October 2016

Structuring PHP Exceptions


Http Error 500, Server error page concept. Man holding banner with error message. Web technology series. I seem to constantly work on improving my habits regarding the use of exceptions. I think it is an area that I haven’t yet fully explored, and it is very difficult to find anything more than very basic explanations and tutorials online. While the consensus is to use exceptions, there is very little information on how to structure and manage them in a larger codebase. The larger and more complex your projects become, the more important it is to start with a proper structure to avoid expensive refactoring later on. Your client will surely be thankful!
In this article, I want to talk about the way I currently set them up and use them in PHP, in the hopes to spark some discussion on the topic and get further feedback.
Why Even Use Exceptions?
Before discussing implementation details, I think it is necessary to mention what the main benefit of exceptions is when compared to something like trigger_error.
Normal PHP errors and warnings come from the procedural world, and they provide one central mechanism to deal with these errors, a function you declare as being the error handler
Source: https://managewp.org/articles/13697/structuring-php-exceptions




source https://williechiu40.wordpress.com/2016/10/26/structuring-php-exceptions/

No comments:

Post a Comment