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 8270313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:32:28+00:00 2026-06-08T06:32:28+00:00

I am working on a project which includes a REST API component. I have

  • 0

I am working on a project which includes a REST API component. I have a controller dedicated to handling all of the REST API calls.

Is there any way to catch all exceptions for that specific controller so that I can take a different action for those exceptions than the rest of the application’s controllers?

IE: I’d like to respond with either an XML/JSON formatted API response that contains the exception message, rather than the default system view/stack trace (which isn’t really useful in an API context). Would prefer not having to wrap every method call in the controller in its own try/catch.

Thanks for any advice in advance.

  • 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-06-08T06:32:29+00:00Added an answer on June 8, 2026 at 6:32 am

    You can completely bypass Yii’s default error displaying mechanism by registering onError and onException event listeners.

    Example:

    class ApiController extends CController
    {
      public function init()
      {
        parent::init();
    
        Yii::app()->attachEventHandler('onError',array($this,'handleError'));
        Yii::app()->attachEventHandler('onException',array($this,'handleError'));
      }
    
      public function handleError(CEvent $event)
      {        
        if ($event instanceof CExceptionEvent)
        {
          // handle exception
          // ...
        }
        elseif($event instanceof CErrorEvent)
        {
          // handle error
          // ...
        }
    
        $event->handled = TRUE;
      }
    
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WiX project that I am working on which includes a Windows
I'm working on a project which includes some slightly more complex dynamic layout of
I'm working on an ASP.NET MVC 2 / .NET 3.5 project which includes SSRS
I'm working on a project which needs to use youtube api. The html and
I'm working on a project which includes generating pie and bar graph charts on
I am currently working on a PHP project which includes extensive database usage. The
I am working on a project, which includes a searching task by entering the
I was working on a project which includes developing an application using java sockets.
I am working on a project built in WPF, which includes an embedded WebBrowser.
Currently I am working on a network project which includes connecting to tcp servers

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.