Jump to content

unable to override php's default exception Messages


ajoo

Recommended Posts

Hi all !

 

I have been using this snippet below to study exceptions:

<?php

mysqli_report(MYSQLI_REPORT_STRICT);

try {
     $connection = new mysqli('localhos', 'root', '', 'test') ;
} catch (Exception $e ) {
     echo "Server Error";
}

?>

If, as in the snippet, I misspell the localhost, I am unable to override the php's own message. If, on the other hand I just misspell say the database name with the host spelt correctly, it overrides the php's default message. ( Default messages in both examples above being different).

 

with the host name misspelt I receive the following warning:

 

 

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in D:\xampp\htdocs\xampp\miscellaneous\exceptions.php on line 6

 

With the host name correct but a wrong database name I get the message defined in the snippet. Namely "Server Error".

 

Kindly help resolve this. 

 

Thanks very much.

Disable all error reporting either with htaccess, php.ini or at the top per php script.

 

htaccess

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

php.ini

error_reporting = off

php scripts, last line helps remove strict errors

error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set('error_reporting', 30711);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.