ntan ntan - 25 days ago 7
PHP Question

is this an endless loop because of the exception?

i have the following code

do {
try {

$result = $class->function_x($params); //this will fire an Exception

break;
}
catch (Exception $e)
{
error_log($e->getMessage());
sleep(5);
}
} while(true);


Is this an endless loop?

The method call fire an Exception so the catch write to error_log and wait for 5 seconds, but because of the Exception the break is not executed (to break the while) and the loop will be endless.

Is that correct or i am missing something?

Answer

If $result = $class->function_x($params); throws Exception it will never go to break;, because it will jump out to catch just after an Exception.

So yes, it looks like endless loop.