B
B
bitbucket2018-07-25 17:24:22
PHP
bitbucket, 2018-07-25 17:24:22

How to catch a construction exception like $noObject->func();?

Please tell me how to catch the exception in this situation:

$html = str_get_html($text);
$html->find('div[class="image"]',0)->find('a',0)->href;

If you just wrap it in try catch - it is not caught
try {
  $html = str_get_html($text);
  $html->find('div[class="image"]',0)->find('a',0)->href;
} catch (\Exception $e) {
    throw new RuntimeException("tag not found");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Konyukhov, 2018-07-25
@bitbucket

catch(\Throwable $t)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question