Maybe I’m missing it somewhere in the PHP manual, but what exactly is the difference between an error and an exception? The only difference that I can see is that errors and exceptions are handled differently. But what causes an exception and what causes an error?
Share
Exceptions are thrown – they are intended to be caught. Errors are generally unrecoverable. Lets say for instance – you have a block of code that will insert a row into a database. It is possible that this call fails (duplicate ID) – you will want to have a "Error" which in this case is an "Exception". When you are inserting these rows, you can do something like this
Program execution will continue – because you ‘caught’ the exception. An exception will be treated as an error unless it is caught. It will allow you to continue program execution after it fails as well.