【发布时间】:2016-03-01 13:40:02
【问题描述】:
我想知道,在 Phalcon 中处理异常的最佳方法是什么?我想为发生错误时创建一个默认错误页面。所以我将/app/public/index.html 重写为:
<?php
error_reporting(E_ALL);
try {
/**
* Define some useful constants
*/
define('BASE_DIR', dirname(__DIR__));
define('APP_DIR', BASE_DIR . '/app');
require_once __DIR__ . '/../vendor/autoload.php';
/**
* Read the configuration
*/
$config = include APP_DIR . '/config/config.php';
/**
* Read auto-loader
*/
include APP_DIR . '/config/loader.php';
/**
* Read services
*/
include APP_DIR . '/config/services.php';
/**
* Handle the request
*/
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
} catch (Exception $e) {
echo 'This is where I want my handling to be';
}
但是,当出现错误时,我不断收到默认的 Chrome 500 错误窗口。该错误被记录到 OS X 的错误控制台,但我没有看到我的回声。我做错了什么?
【问题讨论】:
-
这是引导您的应用程序并捕获异常的正确方法。 您想捕捉什么样的错误? 例如,如果您将数据库密码更改为不正确的密码,您的代码将正常工作。但是如果你犯了一个解析错误,它就不会被捕获。