sentry
errorhandler
对于set_error_handler可以捕获的错误类型,把它们转换成ErrorException,然后再交给handleException处理。
public function handleError($type, $message, $file = '', $line = 0, $context = array())
{
// http://php.net/set_error_handler
// The following error types cannot be handled with a user defined function: E_ERROR,
// E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and
// most of E_STRICT raised in the file where set_error_handler() is called.
if (error_reporting() !== 0) {
$error_types = $this->error_types;
if ($error_types === null) {
$error_types = error_reporting();
}
if ($error_types & $type) {
$e = new ErrorException($message, 0, $type, $file, $line);
$this->handleException($e, true, $context);
}
}
if ($this->call_existing_error_handler) {
if ($this->old_error_handler !== null) {
return call_user_func(
$this->old_error_handler,
$type,
$message,
$file,
$line,
$context
);
} else {
return false;
}
}
return true;
}
利用Raven_Breadcrumbs_ErrorHandler类,实现如果有在sentry的$error_handler->registerErrorHandler()之前注册的set_error_handler,还是会被执行,即先执行sentry的errorHandler,再执行之前注册的errorHandler。
而且如果之前有注册,那么是否display以及是否写log,(即是否调用php internal的error handler)是取决于之前注册的errorhandler返回true还是false。 如果之前没有注册过,那么在sentry处理完之后,默认是仍然会调用php internal的error handler 也就是会display以及写log的
handleException
在sentry中,异常分为两类,一是本身就是异常类,二是通过sentry的errorHandler转化过来的php错误类型的异常。
对于异常的处理,也是会先执行sentry的handleException,也就是通过curl上报到sentry。
然后:
对于本身就是异常类的情况:
上报完成之后,会看之前有没有注册过自己的handleExceptionFunc,如果有就会用handleExceptionFunc处理异常。如果没有,就还是会把异常抛出来。
对于php错误类型的异常:
在上报完成之后,就处理完成了。
handleFatalError
对于set_error_handler捕获不到的致命错误,通过registerShutdownFunction交给handleFatalError处理,也是先转化为ErrorException,然后通过handleException上报到sentry。
registerShutdownFunction可以注册多个,
each will be called in the same order as they were registered.