Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:39:29+00:00 2026-05-17T15:39:29+00:00

In the Zend Framework library, the current practice (circa 1.10.8) is that library components

  • 0

In the Zend Framework library, the current practice (circa 1.10.8) is that library components throw exceptions that extend Zend_Exception.

E.g. the Zend_Layout component throws a Zend_Layout_Exception

In my own ZF library, where I’m adding my own ZF components or extending existing components, I’m throwing a Mylibrary_Exception (it’s not really called that of course 🙂

I can see that they’re going to change some of that in ZF 2.0

http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2

My actual question is this:

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?

should I just

throw new Exception("this is an exception");

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?

application/modules/user/controllers/UserController.php

application/modules/user/forms/UserForm.php

application/modules/user/models/User.php

application/modules/user/views/scripts/index.phtml

application/modules/user/exceptions/Exception.php (class User_Exception)

application/modules/user/exceptions/SuperexampleException.php (class User_Exception_Superexample)

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.

UPDATE:

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:39:30+00:00Added an answer on May 17, 2026 at 3:39 pm

    I’d suggest having some “generic” exceptions like (InvalidParameter, InvalidRange) Good starting point is czech framework called Nette.

    Then add some app/user/action specific exceptions – like

    • InvalidUserInputException – for states where user entered invalid value (like “-1” as quantity in eshop)
    • NotFoundException – for states where something was not found
    • etc.

    Add special member variables to those exceptions – like id or data – and use them to employ exceptions as delivery for error messages.

    $e = new NotFoundException('There is no user %s in here!');
    $e->setUser('Frank');
    throw $e;
    // later in error controller
    if ($e instanceof NotFoundException) {
        // set header to 404, display error message, etc
    }
    

    Good thing is that you can extend the exceptions anyhow you want and catch them in error controller anyhow you want (even better it’s using Interfaces)

    class AccessDeniedExceptionimplements ILogableException
    //...
    throw new AccessDeniedException();
    //in EC
    if ($e instanceof ILoggableException) {
        $this->getLogger()->log($e->getLogMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Zend Framework. I want the current user (if logged in) to
I have some Zend Framework apps running and it's time to add user access
I am integrating Zend Framework into an existing application. I want to switch the
I wrote a command line utility using Zend Framework to do some nightly reporting.
I'm working on an Active Record pattern (similar to RoR/Cake) for my Zend Framework
This article explains how to use Zend in Codeigniter. http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/ I am using XAMPP
I've been trying a bunch of different directory structures for my PHP MVC framework.
I've written several Web MVC apps but never before in PHP, and I'm trying
I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
I have a quick question about how to serve data from a repository in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.