PHP code example of aivo / exceptions

1. Go to this page and download the library: Download aivo/exceptions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aivo / exceptions example snippets


public function responseException(\Exception $exception, Response $response)
{
    if ($exception instanceof \Aivo\BaseException) {
        $data = $exception->__toArray();
        $httpCode = $exception->getHttpCode();

    } else {
        $data = [
            'class' => get_class($exception),
            'error' => $exception->getCode(),
            'message' => $exception->getMessage(),
        ];
        $httpCode = 409;
    }

    return $response->withJson($data)
                    ->withStatus($httpCode);
}

try {
    throw new \Exception('Super secreta');
}
catch (\Exception $e) {
    throw new \Aivo\Exceptions\Word\NotFound(
        $this->logger(),
        $e,
        \Aivo\BaseException::ERROR
    );
}

\Aivo\BaseException::__construct ([\Psr\Log\LoggerInterface $logger = null, $previous = null, $previousLevel = null])