Quick search:


How to handle PntError instances returned by a framework function

If the function is called from application code, you will probably want to check for the error and trigger an E_USER_ERROR or E_USER_WARNING. Example:    $result =& $clsDes->_getPeanutsRunQueryHandler(&$qh);
  if (is_OfType($result, 'PntError')) {
   trigger_error($result->getLabel(), E_USER_WARNING);
   return array();
  }

From generic code it may be better to pass the error to the calling function. This has the advantage that you can trigger the error somewhere else, preferably in the function that was called by the application code. If you trigger an error several calls deep in generic code, the application developer, who should not need to know the internals of generic code, will have a hard time to find out the cause of the error. 

Instead of returning the same PntError instance, you may create a new instance of PntError or a subclass, with an error message of its own and put the old instance as its cause using its setCause method. This way a causal chain of errors may be created that explains why the different layers of generic code could not work properly.

PS. In an eventual php 5 version of phpPeanuts, returning PntError instances will be probably be replaced by throwing exceptions.