ajoo Posted June 8, 2015 Share Posted June 8, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/ Share on other sites More sharing options...
Ch0cu3r Posted June 8, 2015 Share Posted June 8, 2015 It appears throws an Exception and a PHP Warning if the hostname cannot be resolved. Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/#findComment-1513466 Share on other sites More sharing options...
ajoo Posted June 8, 2015 Author Share Posted June 8, 2015 Yes, correct. So how to suppress the php Warning ? I do not wish to use the @ operator for this. Is there any other way ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/#findComment-1513468 Share on other sites More sharing options...
Solution QuickOldCar Posted June 9, 2015 Solution Share Posted June 9, 2015 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); 1 Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/#findComment-1513501 Share on other sites More sharing options...
requinix Posted June 9, 2015 Share Posted June 9, 2015 Make sure you're still logging those errors, though! You may not want the error message to appear on your site but you certainly should be aware of any problems. 1 Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/#findComment-1513504 Share on other sites More sharing options...
ajoo Posted June 10, 2015 Author Share Posted June 10, 2015 Thanks quickold car for the correct answer and requinix for the good advice !! Quote Link to comment https://forums.phpfreaks.com/topic/296705-unable-to-override-phps-default-exception-messages/#findComment-1513595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.