to sum up
The abnormal mechanism provides several very critical benefits:
(1) By focusing on the error handling in the catch statement, you can independently handle the error process from the application process. This also enhances the readability of the code, it looks pleasant. I usually take a very strict strategy to capture all exceptions and abort the script. This allows the desired additional elastic while achieving security and useful anomaly management.
?
(2) Rehabilitation abnormality, pass the abnormal data stream from the low layer to the high layer, that is, the abnormality is transmitted back to the most suitable place to handle exceptions. This looks a bit strange, but in the actual situation, we are often unable to decide how to handle it at an abnormality.
?
(3) Throw / catch provided by the abnormal mechanism avoids the direct return error identifier, the return value of the method can be determined by your class. When other programmers use your code, you can specify a form of returning to his hopes without tired.
?
About author
Matt Zandstra is a writer and is also working in server-side programming and training technical consultants. He and his partner Max Guglielmino operates Corrrosive - a technology company that provides open source, development standard training, planning, and development.
?
Matt is also the author of Sams "TEACH YourSelf PHP in 24 Hours". He is now writing a book about object-oriented programming in PHP.