O'Reilly logo

Zend Framework 2 Cookbook by Josephus Callaars

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling Exceptions – your partner in crime

To find the source of errors, good error handling should be implemented. In this recipe we'll talk about Exception handling within the Zend Framework 2 and how to optimally use it.

Getting ready

We can safely assume that we all know about try-catch and Exceptions, but to make sure nobody is caught out please take a look at the link to the PHP manual in the See also subsection in this section.

How to do it...

Exception handling is not that difficult to use, but it is a very useful tool if used correctly.

Exception classes in Zend Framework 2

Let's take a look at the following example:

<?php // This non existing method throws a couple of Exception, which // is a PDOException, BadMethodCallException and probably ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required