Silex:在中间件中调用 $app->abort() returns 500

Silex: Calling $app->abort() in a middleware returns 500

我不想用Doctrine之类的,所以我直接用PDO。问题是我不知道如何处理异常:调用 $app->abort 以表明它在路由之外不起作用。

<?php

require_once __DIR__.'/../vendor/autoload.php'; 
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

$app = new Silex\Application();

//PDO
try {
    $DBH = new PDO($PartCCTV_ini['db']['dsn'], $PartCCTV_ini['db']['user'], $PartCCTV_ini['db']['password']);
}
catch(PDOException $e) {
    $app->abort(500, 'PDO Error : '.$e->getMessage());            
} 

...

$app->run()

?>
//PDO
try {
    $DBH = new PDO($PartCCTV_ini['db']['dsn'], $PartCCTV_ini['db']['user'], $PartCCTV_ini['db']['password']);
}
catch(PDOException $e) {
    $Exception = $e->getMessage();    
    $app->before(function () use($Exception) {
        throw new PDOException($Exception);
    });
}

"Kolkhoz-style"俄语),但它有效!