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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:03:16+00:00 2026-06-16T03:03:16+00:00

I have a php script lets say during execution the scripts throws an exception.

  • 0

I have a php script lets say during execution the scripts throws an exception. I want my PHP to resume from where it left off (where it had thrown the exception).

Should I put the same execution code in the “catch” part of the code?

On example, is lets say connects to mySQL it fails for connection timed out

   function someCode(){
        $pdostmt = $this->prepare($this->sql);
        if($pdostmt->execute($this->bind) !== false) {
            if(preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
                return $pdostmt->fetchAll($this->fetchOption);
            elseif(preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
                return $pdostmt->rowCount();
   }
   try {
        someCode();
        }   
    } catch (PDOException $e) {  
        //re-execute same code as within the try clause?
        someCode();
    }
  • 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-16T03:03:17+00:00Added an answer on June 16, 2026 at 3:03 am

    First of all one should make clear that an exception is only fatal if it is not caught. Catching an exception does not halt script execution. It merely stops the stack frame in the try block and transfers control to the catch block. From there your script will continue to execute as normal.

    By catching the exception here we still resume normal script execution after the exception is caught…

    try {
      echo "Try...\n";
      throw new Exception("This is an exception");
    } catch(Exception $e) {
      echo "Exception caught with message: " . $e->getMessage() . "\n";
    }
    
    echo "Script is still running...";
    

    There’s another way to handle uncaught exceptions, using an exception handler. However if you don’t use a try and catch statement, execution flow will still be halted. This is the nature of exceptions:

    function myExceptionHandler($e) {
      echo "Uncaught exception with message: " , $e->getMessage(), "\n";
    }
    
    set_exception_handler('myExceptionHandler'); // Registers the exception handler
    
    throw new Exception("This is Exception 1");
    echo "Execution never gets past this point";
    throw new Exception("This is Exception 2");
    throw new Exception("This is Exception 3");
    

    Edit: After clarifying your question I think that I should state what you want is not an exception handler, but you actually don’t want to use Exceptions at all. What you’re trying to do does not require throwing Exceptions at all. Don’t put PDO into exception mode if what you intend to do is just handle the error like that. Exception should only be used to handle exceptional errors. The whole point of an exception is to make sure you keep your promise. For example, if your function makes the promise that it will always return a PDOStatement object and there is a case where it can not possibly do that, then it makes sense to throw an Exception. This lets the caller know that we have reached a point where we can not keep our promise.

    What you want is basic error handling…

    function someCode(){
            $pdostmt = $this->prepare($this->sql);
            if($pdostmt->execute($this->bind) !== false) {
                if(preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql))
                    return $pdostmt->fetchAll($this->fetchOption);
                elseif(preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql))
                    return $pdostmt->rowCount();
            } else {
               return false;
            }
    }
    
    while (someCode() === false) {
      /* Call someCode() until you get what you want */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say we have a dir script.php is a class that is extending a
I have a php script that inserts data from an Android app into a
I have a php script that grabs links from another website. I am storing
Let's say I have a PHP script that does this: $timeNow = 1349852400000; //
I have two websites that will share some resources, lets say, index.php, functions.js and
Well, let's say I have a php-script, that has some select box, and I
I have a PHP script where I have an array of integers, let's say
Lets say I have a plain text file example.txt and I have a PHP
Lets say that we have an image uploaded by the user, the upload script
i want to execute a php script every day. i have a bash script

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.