mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); ...

 try { $result = $this->link->real_escape_string( $this->link->query($query) ); } catch (Exception $e) { Service::error($e); } return $result; 

// option above should work exactly. Will the option work below? If yes, comment on it somehow .. The principle of triggering the exception is not very clear

 try { return $this->link->real_escape_string( $this->link->query($query) ); } catch (Exception $e) { Service::error($e); } 

    1 answer 1

    The principle of triggering Exception is quite simple:

     <?php try { $flag = true; $i = 0; do { $n = rand(0,10); if ($n>4) { throw new Exception('Ошибка на итерации: '.$i, 999); } $i++; } while ($flag); } catch (Exception $e) { echo 'Ошибочка #'.$e->getCode().': '.$e->getMessage(); } 

    When you need to throw Exception , and in catch catch what was thrown.

    More would advise you to search in Google by the phrase "php exception". There is on this topic https://habrahabr.ru/post/264417/ .

    • Pay attention to the fact that the example is not so simple as it seems. There seem to throw exceptions using mysql. Or...? - Vyacheslav Potseluyko
    • yes by any means ... first you need to decide what type of exception (maybe just errors), and then catch them. - Stanislav