title: Throwing exceptions from model/view/controller in a Zend Framework application
body: <p>In the Zend Framework library, the current practice (circa 1.10.8) is that library components throw exceptions that extend <code>Zend_Exception</code>.</p>
  <p>E.g. the <code>Zend_Layout</code> component throws a <code>Zend_Layout_Exception</code></p>
  <p>In my own ZF library, where I'm adding my own ZF components or extending existing components, I'm throwing a <code>Mylibrary_Exception</code>   (it's not really called that of course :)</p>
  <p>I can see that they're going to change some of that in ZF 2.0</p>
  <p><a href="http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2" rel="nofollow noreferrer">http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2</a></p>
  <p>My actual question is this:</p>
  <p>Throughout my MVC application in my controllers/models/views, if I need to throw an exception (and this will be rare, because obviously I'll be handling expected errors in a different way)  - BUT if I do need to throw an exception here, what is the best practice in ZF?</p>
  <p>should I just</p>
  <pre><code>throw new Exception(&quot;this is an exception&quot;);
  </code></pre>
  <p>or should I be creating Exception classes in my ZF modules, similar to how the ZF library is organised. i.e. they have exception classes for each library component, should I have exception classes for each application module?</p>
  <blockquote>
  <p>application/modules/user/controllers/UserController.php</p>
  <p>application/modules/user/forms/UserForm.php</p>
  <p>application/modules/user/models/User.php</p>
  <p>application/modules/user/views/scripts/index.phtml</p>
  <p>application/modules/user/exceptions/Exception.php        (class User_Exception)</p>
  <p>application/modules/user/exceptions/SuperexampleException.php        (class User_Exception_Superexample)</p>
  </blockquote>
  <p>I've never seen anyone do anything like that before in ZF, so I'm not sure if it's a good idea or not.</p>
  <p><strong>UPDATE</strong>:</p>
  <p>To clarify my question further - when raising exceptions in the MVC part of the application (as opposed to the library) - are there any conventions regarding using specific exception classes (like the library does) vs just using the generic Exception class?</p>