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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:24:24+00:00 2026-05-16T23:24:24+00:00

I am about to start implementing error handling into my framework and looking for

  • 0

I am about to start implementing error handling into my framework and looking for some advice on how to build it.

Firstly let me explain how my framework is currently built up:

Im separating the framework startup from the application startup, so any errors caused within the application startup should be handled specifically by a class dedicated to that.

My idea is to have a class called Core_Error_exception witch will set the error reporting to E_ALL as my framework will be strict on errors for PHP 5.3, then as my as my application load I will run a shutdown function function within that class to restore all default values changed.

What im looking to do is capture all errors that are E_*_NOTICE and not E_*_ERROR and then before the application starts I tell the class to stop capturing errors as the Application_Error_Exception will be watching out for errors.

So i will need a way to track all errors including exceptions and triggers and then before the application initializes show a framework debug page.

The kind of class I was looking for is like so:

class Core_Error_Exception
{
    var $previus_error_level,$captured_contents;

    private $stack_trace = array();

    public function Core_Error_Exception()
    {
        $this->previus_error_level = error_reporting(-1);
        set_error_handler(array($this,'_collect_error'));
        set_exception_handler(array($this,'_collect_error'));
        ob_start(array($this,'_capture'));
    }

    public function _collect_error($errno, $errstr, $errfile, $errline, $context)
    {
        $this->stack_trace[] = array(
            array('name' => 'Error ID:',    'value' => $errno),
            array('name' => 'Error String:','value' => $errstr),
            array('name' => 'Error File:',  'value' => $errfile),
            array('name' => 'Error Line:',  'value' => $errline),
            array('name' => 'Context PRE:', 'value' => $context)
        );
        var_dump($this->stack_trace);
    }

    /*
     * _capture is used to capture pre_bufferd content.
     */
    public function _capture($content,$bitfeild)
    {
        if($bitfeild & PHP_OUTPUT_HANDLER_START)
        {
            $this->captured_contents = $content;
        }

        if($bitfeild & PHP_OUTPUT_HANDLER_CONT)
        {
            $this->captured_contents .= $content;
        }

        if($bitfeild & PHP_OUTPUT_HANDLER_END)
        {
            $this->captured_contents .= $content;
        }
        return false;
    }
}

So what im looking to do is to be able to construct this class in a fall-proof way so that any notice errors that may have been triggered will be placed into an array, if an E_ERROR notice is called then this automatically run the shut-down at that point, to prevent more errors being caused.

I will be using a small html template handler where I can pass into that context sets of errors, so Notice errors and a single E_*_ERROR if applicable.

Whats the best way to build this class as in the past I have had some difficulty in doing Error Tracking / Reporting.

Updated: with current class

If errors are triggered such as trigger_error(‘test’,XXX); I want to be able to track all errors until the application launches or an E_USER_ERROR has been triggered.

Sometimes I struggle to fully grasp PHP’s error system, and so on as sometimes i get confused in how to build it so its fall-proof.

  • 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-16T23:24:24+00:00Added an answer on May 16, 2026 at 11:24 pm

    I’m not quite sure about what you’re doing, but the most straightforward way would be to use nested try blocks, along the lines of

    in Class Application:
    
        function run() {
            try {
                --do stuff
            } catch(AppException $e) {
                -- handle application-level exception
            }
            -- all other exceptions fall through
    
    
    in Class Core:
    
        try {
            $core->init();
            $application->run(); <-- calls the above function
            $core->done();
        } catch(Exception $e) {
            --last chance exception handler
            --process exceptions the Application was unable to handle on its own
        }
    

    To be able to catch php built-in errors or trigger_error events this way, you also should always install an errors-to-exceptions handler.

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

Sidebar

Related Questions

I'm about to start looking into developing with the aid of code coverage, and
I am about to start a project for university to build a procedural city
I'm having some trouble implementing DoubleBuffer into my program. Before you faint from the
I am looking into implementing a simple crash report on my application that will
I was implementing a heap sort and I start wondering about the different implementations
I am currently trying to figure out how to best go about implementing an
I'm implementing a version of lzw. Let's say I start off with 10 bit
I am about to start implementing the data access infrastructure of a project that
I am about to start implementing an online web store for a client. The
Please recommend some material about implementing Object-Oriented Databases for dynamic languages (interested in Ruby).

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.