max/var_dump,自定义异常处理。正式环境要怎么用。。

wybwsk

问题描述

这是业务代码。

public function test(): Response {
    try {
        d(123);
        return response('hello webman');
    } catch (Exception $e) {
        throw new BusinessException($e->getMessage());
    }
}

这是自定义的异常处理。

class ApiExceptionHandler extends Handler {
    use AbortHandler;

    public function render(Request $request, Throwable $exception): Response {
        if ($exception instanceof Abort) {
            return \response($this->convertToHtml($exception));
        }
        if ($exception instanceof BusinessException) {
            return \response('asdfasdf');
        }
        return parent::render($request, $exception);
    }
}

本意是想在index中打印一下参数到页面上调试。。
但是插件是通过异常抛出的写法,这样d(123)被抛到BusinessException去了,而不是Abort。

所以。是不是说开发环境调试的时,要把try{}catch{}注掉。。
生产环境时,不要用d,就用print_r,在命令行显示,不影响页面?
但是这里我想要中断,调试时,不执行后面的代码,直接抛出。这个要怎么弄?

726 1 0
1个回答

又有心跳

return

年代过于久远,无法发表回答
🔝