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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:44:14+00:00 2026-06-15T18:44:14+00:00

so a function crashes sometimes ( uncaught exception ) and i want to re-call

  • 0

so a function crashes sometimes ( uncaught exception ) and i want to re-call it 2 times when that happens with a delay of 1 seconds let’s say. Here’s is the code but it doesn’t seem to work:

$crashesn = 0;

function checkNum($number) {
    echo $number . "<br>";
    if ($number>1) {
        throw new Exception("Value must be 1 or below");
    }
    return true;
}

try {
    checkNum(2);
    echo 'If you see this, the number is 1 or below';
}

catch(Exception $e) {
    $crashesn++;
    echo "crashes number:".$crashesn."<br>";
    if ($crashesn <= 2) {
        sleep(1);
        checkNum(2);
    } else {
        echo "MESSAGE: " .$e->getMessage();
    }
}

checknum is the function which throws the exception ( here it crashes every time by throwing an exception ). The problem is, when I run this piece of code, i still get on my page an error message

Fatal error: Uncaught exception 'Exception' with message 'Value must be 1 or below' in G:\fix\ta_dll\test.php:30 Stack trace: #0 c:\wwwl\test.php(45): checkNum(2) #1 {main} thrown in c:\php\test.php on line 30

instead of a “MESSAGE: ERROR DESCRIPTION”. the “crashes number” line only gets printed once, not twice.

anyone knows what I am doing wrong ?

  • 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-15T18:44:15+00:00Added an answer on June 15, 2026 at 6:44 pm

    Try with a loop instead

    for ($crashes = 0; $crashes < 3; $crashes++) {
        try {
            checkNum(2);
            echo 'If you see this, the number is 1 or below';
            break;
        }
        catch(Exception $e) {
            echo "crashes number:" . $crashes . "<br>";
            if ($crashes < 2) {
                sleep(1);
            } else {
                echo "MESSAGE: " . $e->getMessage();
            }
        }
    }
    

    When checkNum() returns properly, the for loop is left with the break. Otherwise, when an exception is thrown, break is skipped and the loop repeats.

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

Sidebar

Related Questions

Sometimes my script, that sends push notifications crashes with error: Warning: stream_socket_client() [function.stream-socket-client]: SSL
I'm using libxml2 and C++. The following function crashes here at return (char*)cur->content; .
I've this assignment to implement strcmp function. Sometimes it runs okay but other times
I want to call the following code from my pages, and sometimes pass a
Sometimes I start a MATLAB script and realize too late that it is going
UPDATE Here Ajax receives some responseimage from the server success: function(responseimage) { ..... }
I ported my application from VC++7 to VC++9 recently. Now it sometimes crashes at
OK, so this code below sometimes crashes on the line below //bug!! The error
This code works some of the time, but then sometimes crashes with a EXC_BAD_ACCESS
I found the function here . It accepts an array of integers and returns

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.