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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:48:15+00:00 2026-05-23T23:48:15+00:00

Back story: I have a class that handles a database query. The problem is

  • 0

Back story: I have a class that handles a database query. The problem is that the query is only executed when needed, so this may sometimes be a bit far away from the place it’s created. Now if the wrapped SQL query fails, it becomes difficult to trace it back to it’s origin.

Now the idea is this: I’ll create a generic exception object (which gives me backtrace and everything) when creating that wrapper. When something happens during the actual execution, the pre-generated exception can be used to find the source of the problem when debugging.

This inevitably leads to the question: How expensive is it to generate an Exception object beforehand? Is it even a smart thing to do? How would you debug deferred SQL execution?

To clarify the process, here’s some pseudo code:

$list = new QueryWrapper("SELECT ...");

$list->setPage(5);

// Later...
foreach ($list as $entry) { ... }

Only when the foreach actually accesses $list is the query executed.

Update: Here’s a minimalistic implementation:

public function __construct($query, ... $params = array()) {
        ... 
        $this->createTrace     = new \Exception();
}

// called by the Iterator's rewind()  
private function runQuery() {
    try {
        // execute query;
    }
    catch(\Exception $e) {
        throw new \Exception(
            sprintf(
                'Exception thrown after SQL error (created as %s)',
                $this->createTrace->getTraceAsString()
            ),
            0, $e
        );
    }
}
  • 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-23T23:48:16+00:00Added an answer on May 23, 2026 at 11:48 pm

    Instantiating an Exception which might be thrown later sounds like a rather unusual idea and is likely not what I would expect. I mean, the normal case would be to NOT throw an exception. So, most of the time you would create an Exception which is likely be never thrown/used.

    An Exception which is thrown later in program flow will give you the stack trace anyway, so in my opinion: dont bother and dont do that.

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

Sidebar

Related Questions

The Back Story I have some decimal values which I am displaying as strings
Backstory: I have a PKCS#12 (p12) certificate with a symmetric cipher (password) that I
back story: I am designing a portfolio website for myself. on its home page,
Back in VB6, I wrote a few functions that would let me code without
I'm working with data that is natively supplied as rational numbers. I have a
I have a UserControl that incorporates a textbox. I want to set the keyboardfocus
First i have declare that i am new to javascript. I have created a
I have a modelform that will either create a new model or edit an
Wondering if I'm going about this the right way or not. I have 3
Here is the scenario. I have a WCF service, when this service is called

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.