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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:35:14+00:00 2026-06-12T19:35:14+00:00

Is this how you would pass a value (username in example below) to a

  • 0

Is this how you would pass a value (“username” in example below) to a custom exception? The question being Would I use __construct()? Is using a custom exception for checking whether an important variable is set an overkill?

class customException extends Exception {

    public function __construct($e) {
        parent::__construct($e); // makes sure variable is set? [1]
        $this->e = $e;
    }
    public function redirect_user() {
        if($this->e === "username") {
            header("Location: ");
        }
    }
}

class testing {

    public function test() {
        try {
            if(!isset($_POST['username'])) {
                throw new customException("username");
            }
        }
        catch(customException $e) {
            $e->redirect_user();
        }
    }
}

[1] http://php.net/manual/en/language.exceptions.extending.php#example-266

On a side note, what’s the purpose of parent::__construct($e)? Wouldn’t that be redundant?

  • 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-12T19:35:15+00:00Added an answer on June 12, 2026 at 7:35 pm

    There is no reason for your constructor at all. I would suggest using $this->getMessage() to access the value you are trying to set to $this->e.

    So do something like this:

    class customException extends Exception {
        public function redirect_user() {
            if($this->getMessage() === "username") {
                print_r("Header");
            }
        }
    }
    

    It is much more straightforward and only extends the functionality of the base class rather than unnecessarily overriding the constructor.

    That being said, I personally don’t like the thought of using exceptions to execute application flow logic like you are doing. To me, custom Exceptions are useful to interface with custom logging systems, or to be able to log aspects of your application’s state that are not available via the default Exception class.

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

Sidebar

Related Questions

My brain is fried, so I thought I would pass this one to the
This would be an example of database table: PHP script should limit query result
I would like to apologize if the duplicate of this question exist. i tried
Is it better to use JQuery for form submission? For example: <input type=text id=username
update: I would like to pass the var value to the server hello, same
I have a javascript like this, used i a bookmarklet: window.location=URL document.getElementById('username-id').value = 'User'
I have written this ajax request for username checking... function check_username() { var username
Consider this line: std::wcout << Hello World!; Is it OK to pass char* or
This would be it : y'(t)=y(t)/t-t^2/y^2*t y(1)=1 i have tried: function hazi3b() [T,Y] =
This would be easy to do with regular array with a simple for statement.

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.