duan89197 2015-12-28 15:08
浏览 87

如何在Laravel 5中处理PDOException

I've modified Exceptions/Handler.php to:

    <?php namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class Handler extends ExceptionHandler {

    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
    'Symfony\Component\HttpKernel\Exception\HttpException'
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(Exception $e)
    {
        return parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {

        if($e instanceof NotFoundHttpException)
        {
            return response()->view('errors/404');
        }

        elseif ($e instanceof ErrorException) {
            return response()->view('errors/404');
        }

        elseif ($e instanceof ModelNotFoundException) {
            return response()->view('error_log(message)ors/404');
        }

        elseif($e instanceof PDOException)
        {
            return Redirect::to('install.php');
        }

        elseif($e instanceof QueryException)
        {
            return Redirect::to('install.php');
        }

        else return response()->view('errors/error');


    }

trying to redirect to installation whenever application makes PDOException, but I'm just getting general error view (errors/error - from the last line of the code above).

Is there a way to cach specifically PDOException error?

  • 写回答

3条回答 默认 最新

  • doulechou0700 2015-12-28 15:38
    关注

    I think I've found the solution:

    just put

    use PDOException; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?