Documentation


SEARCH

TABLE OF CONTENT

    1. Getting started 2. Basic concepts 3. Request dispatching 4. Context container 5. Dual MVC 6. Component model: 7. Security 8. Configuration 9. Session handling 10. I18n 11. Cache 12. Logging 13. Error handling 14. Advanced Topics 15. API reference

      Tutorials: Frequently Asqued Questions

      See also:


      The Error Table

      Classifying Exceptions

      Table of Contents

      The Error Table

      Exceptions can be declared and classified in the errors.xml file (app/config/errors.xml).
      i.e.

      1. <?xml version "1.0" standalone="yes"?>
      2.  
      3. <configuration>
      4.  
      5.   <errors>
      6.   
      7.     <!-- Common errors -->
      8.     <error-group id="ERR_MODEL_ERRORS" exception-class="MyModelExceptionClass">
      9.       <error code="75001" id="ERR_INVOICE_CANNOT_BE_EMPTY" />
      10.       <error code="75002" id="ERR_INVOICE_WRONG_DATE" />
      11.       <error code="75003" id="ERR_INVOICE_NOT_FOUND" />
      12.       <error code="75004" id="ERR_CUSTOMER_NOT_FOUND" />
      13.       ...
      14.     </error-group>
      15.  
      16.     <error-group id="ERR_SECURITY_ERRORS" exception-class="MySecurityExceptionClass">
      17.       <error code="76002" id="ERR_WRONG_USERNAME_OR_PASSWORD" />
      18.       <error code="76008" id="ERR_ACCESS_LOGIN_REQUIRED" />
      19.       ...

      What we're doing in the errors.xml is to group exceptions according to their nature. Each group has an specific Exception class that will be used in case an exception within the group is raised to. In the example above, look the exception-class attribute declare for each group.

      To use an error table has 3 main advantages:

      1. It decouples the usage of an exception class or the other one depending on a given error, making it transparent to our application.
      2. It eases the internationalization of our exception messages. See pkg.
      3. It eases the maintenance of all our exceptions within a single place as well as the assignment of error codes

      The Exception Factory

      The __ExceptionFactory is a class in charge of create exceptions according to the error table.

      It basically receives a given error code in order to create the most appropriate exception according to how it has been declared in the error table

      i.e.

      1. if($error_authentication)) {
      2.  
      3.           ->createException('ERR_WRONG_USERNAME_OR_PASSWORD');
      4.  
      5. }

      In this example, the __ExceptionFactory takes as argument an exception code (ERR_WRONG_USERNAME_OR_PASSWORD), so it will create a MySecurityExceptionClass exception supposing we are using the error table above.

      It's also important to note that, in our example, the MySecurityExceptionClass will have the error code 76002 as we have declared in our error table