G
G
ganbatte2018-11-08 08:15:19
PHP
ganbatte, 2018-11-08 08:15:19

How to continue script execution when function fails?

Here is my code

<?php
include("simple_html_dom.php");
function nas($nas, $name)
{
set_time_limit(0);
$pog='https://'.$nas;
  $ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $pog );
$string = curl_exec($ch);
curl_close($ch);
$html = str_get_html($string);
$pogoda = $html->find("div.values", 0)->children(4)->plaintext;
}
?>
echo nas(23123,123123);
echo nas(2342,234);

When an error occurs in this function, the execution of the script stops, how can I fix it, I want to continue the function after the error ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Korobkov, 2018-11-08
@mkorobkov

Read about try catch.

L
Lander, 2018-11-08
@usdglander

try {
    echo nas(23123, 123123);
} catch (\Exception $e) {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question