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

  • SEARCH
  • Home
  • 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 6608909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:35+00:00 2026-05-25T19:39:35+00:00

I have a service layer which is responsible for handling exceptions. The question is,

  • 0

I have a service layer which is responsible for handling exceptions.

The question is, should I be handling exceptions in the service layer and how can I pass an appropriate exception message to a view?

class App_Service_Feed {
  function create() {
    //...
    try {
      $feed->getMapper->insert();
    } catch (Zend_Db_Statement_Exception $e) {
      //what do I return here?        
    } catch (Exception $e) {
      //what do I return here?
    }
  }
}

I’m thinking of returning a response object of some description, so that in my controller I manipulate this.

class App_Controller {
  //...
  $response = $service->create();
  if($response->status) {

  }
}

Alternatively, I’m wondering whether to handle exceptions in the controller…

  • 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-25T19:39:35+00:00Added an answer on May 25, 2026 at 7:39 pm

    Even better than the way of jason bourne (yeah):

    class App_Service_Feed {
      function create() {
        //...
        try {
          $feed->getMapper->insert();
        } 
        catch (Zend_Db_Statement_Exception $e) 
        {
          throw new App_Service_Feed_Exception("Your own message", NULL, $e);      
        } 
        catch (Exception $e) 
        {
          throw new App_Service_Feed_Exception("Your other message", NULL, $e);
        }
      }
    }
    

    Why is this better?

    • You are using your own Exception class (extending Zend_Exception). So you can immediately see where the exception was thrown and you can build in your own additional checks, etc.
    • You are passing the last exception along to have more history information (trace) about Exception.

    The best way to implement Exceptions is to have a hierarchy of extending Exception classes.

    App_Exception extends Zend_Exception
    App_Service_Exception extends App_Exception
    App_Service_Feed_Exception extends App_Service_Exception
    

    So every folder contains an Exception.php. This way you can catch and rethrow Exceptions on every level, if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service, business and data access layer. In which layer should I
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
I am using declarative transactions in Spring. I have a service layer which is
I have a repository layer that is responsible for my data-access, which is called
I have a REST web-service interface that calls-down to a service layer which orchestrates
We have an application in which we have created a service layer with most
I have four lists in my webflow, which I load from my service layer.
I have a Web Service ( model-layer ) which communicates with Database. This module
I have a WCF service layer which uses pure DTOs. On the server side,
For background, I have a Data layer and Service layer loosely based on Rob

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.