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

  • Home
  • SEARCH
  • 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 7637239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:53:13+00:00 2026-05-31T07:53:13+00:00

I know this is a weird on, but in my code, i have development

  • 0

I know this is a weird on, but in my code, i have development mode errors, and production mode errors. This is the function i have:

private function error($message, $mysql_error = null){
    if( DEVELOPMENT_MODE ){
        $exp = new Exception();
        $trace = $exp -> getTrace();
        array_shift( $trace ); // removes this functions from trace
        $data["Error Mg"] = $message;
        $data["MySQL Er"] = ( is_null ( $mysql_error ) ) ? "" : $mysql_error;
        array_unshift($trace, $data );
        fkill( $trace );  // formats array and then dies
    }
    else{
        throw new Exception ( $data );
    }
}

I wrote this function in my database class, so that if an error happens, I don’t have to provide the check if we’re in development mode or not!

So I thought I could externalise the re-usable code. However, because I’m throwing an exception from this function, I’m basically just using a function, that will return a thrown error. Pretty useless in production mode.

I would have to do this every time i want to use it:

try{
    $this -> error( "Invalid Link After Connect.", mysql_error () );
} catch ( Exception $exp ){
    throw $exp;
}

RATHER THAN JUST

$this -> error( "Invalid Link After Connect.", mysql_error () );

so to avoid writing a try … catch block for every error function I want to call… is there any way to throw the exception 2 levels up?

  • 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-31T07:53:14+00:00Added an answer on May 31, 2026 at 7:53 am

    An exception will automatically travel up the call chain until it reaches the highest level. If it’s not caught there, program execution terminates due to an uncaught exception. The whole point of exceptions is to be able to have errors bubble up. You don’t need to throw harder or do anything special to “throw it up 2 levels”, that’s what it does by definition.

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

Sidebar

Related Questions

Okay, I know it is weird but when I put this code between <head
I know this is a weird question to ask, but I would like to
I know this one is the weirdest of all weird questions I have asked
I have a weird problem, and I don't know if this is the default
I know this isn't strictly a programming question but y'all must have experienced this.
I know this is not programming directly, but it's regarding a development workstation I'm
I know this is a weird question, but let me explain more. I use
I'm getting this weird error: error C2663: 'sf::Drawable::SetPosition' : 2 overloads have no legal
I know this may sound like a weird question to ask but I would
I have this weird failing coffeescript, from this demo . The demo code works

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.