master

laravel/framework

Last updated at: 29/12/2023 09:25

ViewException.php

TLDR

This file contains a class called ViewException that extends the ErrorException class. It has two methods:

  • report: This method is responsible for reporting the exception.
  • render: This method is responsible for rendering the exception into an HTTP response.

Methods

report

This method is used to report the exception. It retrieves the previous exception and checks if it has a report method. If the method exists, it calls it using the Laravel container instance. If the previous exception does not have a report method, it returns false.

render

This method is used to render the exception into an HTTP response. It retrieves the previous exception and checks if it has a render method. If the method exists, it calls it passing the $request parameter.

Classes

ViewException

This class extends the ErrorException class. It is used to handle view-related exceptions in Laravel applications. It provides the report and render methods for reporting and rendering exceptions, respectively.

<?php

namespace Illuminate\View;

use ErrorException;
use Illuminate\Container\Container;
use Illuminate\Support\Reflector;

class ViewException extends ErrorException
{
    /**
     * Report the exception.
     *
     * @return bool|null
     */
    public function report()
    {
        $exception = $this->getPrevious();

        if (Reflector::isCallable($reportCallable = [$exception, 'report'])) {
            return Container::getInstance()->call($reportCallable);
        }

        return false;
    }

    /**
     * Render the exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response|null
     */
    public function render($request)
    {
        $exception = $this->getPrevious();

        if ($exception && method_exists($exception, 'render')) {
            return $exception->render($request);
        }
    }
}