ntan ntan - 1 year ago 70
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

catch (Exception $e)
} 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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download