这是预期的行为为Laravel。 Laravel会将任何错误转换为ErrorException
实例。以下是Illuminate/Foundation/Bootstrap/HandleExceptions.php
类中的bootstrap()
方法。
public function bootstrap(Application $app)
{
$this->app = $app;
error_reporting(-1);
set_error_handler([$this, 'handleError']);
set_exception_handler([$this, 'handleException']);
register_shutdown_function([$this, 'handleShutdown']);
if (! $app->environment('testing')) {
ini_set('display_errors', 'Off');
}
}
的error_reporting(-1);
将设置PHP报告所有错误(阅读更多here)。
虽然这部分代码:
set_error_handler([$this, 'handleError']);
将设置一个自定义错误处理程序。如果您检查handleError()
方法,很明显Laravel会将任何错误转换为ErrorException
实例。
public function handleError($level, $message, $file = '', $line = 0, $context = [])
{
if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line);
}
}
了解更多关于自定义错误处理程序here。
希望这个清楚的事情。 :)
如果抛出特定的异常,您可以覆盖其处理程序的行为与默认行为不同。请参阅Laravel Docs中的[this](https://laravel.com/docs/5.3/errors#the-exception-handler)。什么是异常类? –
@IlkerMutlu类是ErrorException。这也很奇怪,因为它是一个普通的例外。 –
然后你可以做的就是将''''ldap_bind'''调用包装在try catch块中。 –