Http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning
One possibility is to set your own error handler before the call and restore the previous error handler later withRestore_error_handler().Set_error_handler(function() {/*Ignore Errors*/});d Ns_get_record ();Restore_error_handler(); You could build in this idea and write a re-usable error handler that logs the errors forYou.Set_error_handler([$logger, ' Onsilencederror ']);d Ns_get_record ();Restore_error_handler(); Turning errors into exceptionsyou can Use Set_error_handler() and the ErrorexceptionclassTo turn all PHP errors into exceptions.Set_error_handler(function($errno,$errstr,$errfile,$errline,Array $errcontext) { //error is suppressed with the @-operator if(0 = = =error_reporting()) { return false; } Throw NewErrorexception ($errstr, 0,$errno,$errfile,$errline);});Try{Dns_get_record ();}Catch(errorexception$e) { // ...}
The important thing to note when using your own error handler are that it'll bypass theerror_reportingSetting and pass all errors (notices, warnings, etc.) to your error handler. Can set a second argument onSet_error_handler() toDefineWhich error types you want to receive, or access the CurrentSetting using ... =error_reporting() inside the error handler.
[PHP] Try-catch Exceptiong Handler