Friday, November 19, 2010

Why exception handling is important in php?

    I work as a professional programmer for 10 years and in those 10 years I met a bunch of different developers. In plenty of them, especially in web / php developers, I could notice a lack of understanding of the concept of throwing and catching exceptions and what does it serves for. Of course, the first I noticed it at myself. In this blog I would like to point out a number of useful things that proper use of the exception can make, and which were slipping from my hands for a few years too.

    Exceptions are providing a standardized way to control problematic processes and they are reducing the possibility of fatal errors in the application. If process throws exception, you are forced to handle situation in your application, and it will automatically reduce the possibility that some problem sleeps out whit out being processed. When you're working with exceptions, you are handling problems at low level, so it will not make you problems with your higher layers, e.g displaying error messages to user.

    Work with exceptions make it easier to fix bugs when they happen. Errors in applications will always happen, especially in the real world of short deadlines and often requirement specification changes. However, when something goes wrong in your application, the question is when will you and will you even notice at all that something went wrong? And, also, how quickly you will know exactly what happened and what needs to be corrected? If you are working with the exceptions, this can be quite clear and painless issue that you will quickly and efficiently solve.

    PHP only since version 5 delivers the work with conventional try / catch system and it's quite a big problem for those developers who have not dealt with eg Java or C# too. In future posts I'll try to explain few simple general rules to follow that will help you to make the exceptions are not the problematic to you, but a tool which will increase your speed and quality.

  
  
  
 

1 comment:

  1. Indeed a very good basic. Once can also refer at http://www.techflirt.com/php/php-try-catch.html for more basic aspects

    ReplyDelete