Exceptions and Error Handling

We know generally from our programming languages concepts, that the errors are generated by the compiler of a programming language, when we make mistakes in writing correct code.These errors are known as System generated errors. 

But sometimes in our applications, as we have learnt from our previous lesson of PHP that there are validation errors on User Data. So we should be treating those errors in such a way, so they are better managed  and displayed to the User. These kind of errors are known as Exceptions. 

Thus we have in PHP built in 'Exception' Class and its related Methods, which can be used and then we have Error handling mechanism, the "try Catch' block provided by PHP to report those errors to the user in a decent way.

We will show you with the following snippet of code how we can throw 'Exceptions' and how they will be reported as an error by the help of 'try Catch' block.

Get hands-on with 1200+ tech skills courses.