Search code examples
laravelexceptionwhoops

Laravel package whoops exception


In my Laravel package I have this code:

try {
    $var_msg = "Exception example";
    throw new InvalidNameException($var_msg);
}
catch (InvalidNameException $e) {
    abort(403, $e->getMessage());
    //report($e);Exception Log
}

The error is displayed as html error page. But, I'd like to report the error as an whoops error.

Error Image


Solution

  • Take this code as reference.

        $whoops = new \Whoops\Run();
        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
    
        // Set Whoops as the default error and exception handler used by PHP:
        $whoops->register();
    
        throw new \RuntimeException("Oopsie!");