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

The Archive Base Latest Questions

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

aka, Seeking generic Error Handler (ΟΚ to use commercially) I doubt that I am

  • 0

aka, Seeking generic Error Handler (ΟΚ to use commercially)

I doubt that I am the best PHP programmer around, so, although I have my own generic error handler for set_error_handler(), I wondered what others do and if there is a “best” (sorry if that sounds subjective – I just want to draw out general approaches (but even the ‘best practices’ tag has been removed from SO)).

To be objective about it, here’s what I think is needed. Please correct me if I am wrong & point me to some good code if you agree.

  • I want to capture as much information as possible – without knowing what the error was.

  • so, for instance, it makes sense to dump the call stack.

  • and $_GET, $_POST and $_SESSION.

  • and I want the call stack & Globals to be pretty-printed

  • I want some ‘plain-text’ layout, not CSS & fancy JS to expand/collapse the information. My users may have to cut/paste into email or even print out & fax.

  • I would like to be able to add a header of my own devising, preferably as a parameter, but I can hack the code if need be. The header might include the program version, timestamp, etc (and, in my case, I have an audit track, so I can include the user’s last few actions, which led to the crash).

  • some users may allow my code to auto-email the report, some may wish to preview it forst & them email it and some may not want me to send email.

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

    I suggest to go the “Exceptions” way.

    Throw exceptions when there’s a user error, and you can convert php errors into exceptions, like this:

    function exception_error_handler($errno, $errstr, $errfile, $errline ) {
        throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
    }
    set_error_handler("exception_error_handler");
    

    Albeit that this kind of behaviour works best in an OOP kind of environment. If you don’t have a single point of entry (like a frontcontroller), you may also catch loose exceptions with this:

    function myException($exception)
    {
        echo "<b>Exception:</b> " , $exception->getMessage();
    }
    
    set_exception_handler('myException');
    

    Simple debugging with exceptions would go something a bit like this:

    function parseException($e) {
        $result = 'Exception: "';
        $result .= $e->getMessage();
        $trace = $e->getTrace();
        foreach (range(0, 10) as $i) {
            $result .= '" @ ';
            if (!isset($trace[$i])) {
                break;
            }
            if (isset($trace[$i]['class'])) {
                $result .= $trace[$i]['class'];
                $result .= '->';
            }
            $result .= $trace[$i]['function'];
            $result .= '(); ';
            $result .= $e->getFile() . ':' . $e->getLine() . "\n\n";
        }
    
        return $result;
    }
    

    From there evaluating globals etc. is a walk in the park. You might look for inspiration to the Symfony Framework Debug Toolbar, which offers many of these requests.

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

Sidebar

Related Questions

Static metaprogramming (aka template metaprogramming) is a great C++ technique that allows the execution
I'd like create a kernel(aka named events) from C#. Do I have to interop
Are there any ports to WPF of Silverlight's MultiScaleImage (aka DeepZoom)? Have Microsoft road-mapped
I need an encoder that can convert mp3 files to he-aac (aka aac+). So
AKA - What's this obsession with pointers? Having only really used modern, object oriented
C++ is all about memory ownership - aka ownership semantics . It is the
I'm trying to do a subselect in pgsql aka postgresql and the example I
I'm looking at using CompositeWPF ( http://www.codeplex.com/CompositeWPF ) - aka Prism, to build an
I'm looking at adding Visual Studio Database Edition (aka. VSDE) to my version of
From a COM library (Microsoft Office Document Imaging aka MODI) I receive an image

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.