I'm scraping some data from a website using QueryPath. However, every so often I receive the error message below and the script terminates.
PHP Catchable fatal error: Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument, null given, called in ....inc/QueryPath/QueryPath/CSS/DOMTraverser.php on line 417 and defined in ....inc/QueryPath/QueryPath/CSS/DOMTraverser.php on line 467
The error doesn't give me any clues as to which line of my code the error is coming from, but assuming it was coming from $outHtml = htmlqp($outHtml);
I tried prefixing the htmlqp command with @htmlqp
.
This didn't work, so I then tried wrapping htmlqp in a catch{} statement which didn't seem to help either.
All I want to do is ignore the error and continue rather than having the script bomb out. Help!
It's a catchable fatal error .. so catch it.
If you catch it you can get a full stacktrace.
Ex:
try {
thisfunctionthrowsanexception();
} catch (Exception $e) {
var_dump(get_class($e));
echo $e->getTraceAsString();
}
@
hides errors. You don't ever want to have to use that.
I was just trying to solve the opposite problem in some production code: the type hinting is not working at all. I traced the culprit down to the following code:
set_error_handler('errorHandler');
function errorHandler($errno, $errstr, $errfile, $errline) {
// Whole bunch of irrelevant code
// ...
return;
}
It handles the error... by essentially doing nothing!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.