zyc's avatar
Level 1

$exception instanceof AuthenticationException not working as expected

Hi, guys. I am new to Laravel. Just installed 5.5 and try to catch the AuthenticationException in App\Exceptions\Handler like below


public function render($request, Exception $exception)
{
    if ($exception instanceof AuthenticationException) {
        //Do something
    }

}

The problem is ($exception instanceof AuthenticationException) always return false.
dd($exception instanceof AuthenticationException) //return false.
When I dd($exception) I got

AuthenticationException{
    #gurad...
    ....
    .....
}

get_class($exception) return \Illuminate\Auth\AuthenticationException
However,
dd($exception instanceof Exception) //return true.

Please help. Thanks.

0 likes
1 reply
sutherland's avatar

Are you importing AuthenticationException at the top of your handler?

use Illuminate\Auth\AuthenticationException;

Please or to participate in this conversation.