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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:38:52+00:00 2026-06-09T11:38:52+00:00

I’ve written the following custom Exception handler: namespace System\Exception; class Handler extends \Exception {

  • 0

I’ve written the following custom Exception handler:

namespace System\Exception;

class Handler extends \Exception {


    public static function getException($e = null) {

        if (ENVIRONMENT === 0 && is_object($e)) {       
            $message  = "<p>";
            $message .= "Exception: " . $e->getMessage();
            $message .= "<br />File: " . $e->getFile();
            $message .= "<br />Line: " . $e->getLine();
            $message .= "<br />Trace: " . $e->getTrace();
            $message .= "<br />Trace as string: " . $e->getTraceAsString();
            $message .= "</p>";
        } else {
            $message  = '<h1>Exception</h1>';
            $message .= '<p>There was a problem.</p>';
        }

        @require_once('header.php');
        echo $message;
        @require_once('footer.php');

        exit();

    }


    public static function getError($errno = 0, $errstr = null, $errfile = null, $errline = 0) {
        if (ENVIRONMENT === 0) {        
            $message  = "<p>";
            $message .= "Error: " . $errstr;
            $message .= "<br />File: " . $errfile;
            $message .= "<br />Line: " . $errline;
            $message .= "<br />Number: " . $errno;
            $message .= "</p>";
        } else {
            $message  = '<h1>Error</h1>';
            $message .= '<p>There was a problem.</p>';
        }

        @require_once('header.php');
        echo $message;
        @require_once('footer.php');

        exit();

    }   


    public static function getShutdown() {
        $last_error = error_get_last();
        if ($last_error['type'] === E_ERROR) {
            self::getError(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
        }
    }


}

and have indicated that I want to use this class and its methods for processing all exceptions and errors generated by the system in the following way:

set_exception_handler(array("System\Exception\Handler", "getException"));
set_error_handler(array("System\Exception\Handler", "getError"), -1 & ~E_NOTICE & ~E_USER_NOTICE);
register_shutdown_function(array("System\Exception\Handler", "getShutdown"));

I have also indicated that I don’t want errors to be displayed on the screen and wand to report all of the errors:

ini_set('display_errors', 'Off');
error_reporting(-1);

My question now is – do I still need to use the try { } catch () { } statement in order to catch any exceptions and errors? I know that the above is most probably not a bullet proof, but seem to be working so far without any try / catch statement by processing all uncaught exceptions and errors.

Also – is there any disadvantage by using custom exception handler and letting it catch all uncaught exceptions rather than doing this via try {} catch (i.e. performance / security etc.)?

  • 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-09T11:38:53+00:00Added an answer on June 9, 2026 at 11:38 am

    You don’t have to, but you cannot recover – using try/catch gives you the advantage of reacting to particular exception (for example file not found in some_custom_session_handling() might be a good place to use try/catch and log out such user without session file).

    So the advantage is that you have prettier messages. The downside is that you treat exceptions always the same. It’s not bad in itself, and should not degradate performance or security, but it misses the point of using exceptions in the first place.

    However, it does not exclude using try/catch where you might want them, so I’d say it’s a good failover solution, but should be avoided as a try/catch replacement

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.