PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Testing for Exceptions in the Response Object

As mentioned earlier, by default, exceptions caught during dispatch are registered with the response object. Exceptions are registered in a stack, which allows you to keep all exceptions thrown -- application exceptions, dispatch exceptions, plugin exceptions, etc. Should you wish to check for particular exceptions or to log exceptions, you'll want to use the response object's exception API:

  • setException(Exception $e) allows you to register an exception.

  • isException() will tell you if an exception has been registered.

  • getException() returns the entire exception stack.

  • hasExceptionOfType($type) allows you to determine if an exception of a particular class is in the stack.

  • hasExceptionOfMessage($message) allows you to determine if an exception with a specific message is in the stack.

  • hasExceptionOfCode($code) allows you to determine if an exception with a specific code is in the stack.

  • getExceptionByType($type) allows you to retrieve all exceptions of a specific class from the stack. It will return FALSE if none are found, and an array of exceptions otherwise.

  • getExceptionByMessage($message) allows you to retrieve all exceptions with a specific message from the stack. It will return FALSE if none are found, and an array of exceptions otherwise.

  • getExceptionByCode($code) allows you to retrieve all exceptions with a specific code from the stack. It will return FALSE if none are found, and an array of exceptions otherwise.

  • renderExceptions($flag) allows you to set a flag indicating whether or not exceptions should be emitted when the response is sent.

Zend Framework